X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fpolyfills%2Fconsole.js;h=589a8397eac6988f2fdef012800e5b40cd0ae16b;hb=f0e472002843b5e61aa9467f97f755280c91a46b;hp=4a6f5423a482f0a641034ffa568af6e4d6a3e697;hpb=3123ca57f71d145bb5bcc4a2f754d3dff3225346;p=dygraphs.git diff --git a/src/polyfills/console.js b/src/polyfills/console.js index 4a6f542..589a839 100644 --- a/src/polyfills/console.js +++ b/src/polyfills/console.js @@ -1,8 +1,10 @@ // Console-polyfill. MIT license. // https://github.com/paulmillr/console-polyfill // Make it safe to do console.log() always. -(function(con) { +(function(global) { 'use strict'; + global.console = global.console || {}; + var con = global.console; var prop, method; var empty = {}; var dummy = function() {}; @@ -10,6 +12,9 @@ var methods = ('assert,clear,count,debug,dir,dirxml,error,exception,group,' + 'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' + 'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(','); - while (prop = properties.pop()) con[prop] = con[prop] || empty; - while (method = methods.pop()) con[method] = con[method] || dummy; -})(this.console = this.console || {}); // Using `this` for web workers. + while (prop = properties.pop()) if (!con[prop]) con[prop] = empty; + while (method = methods.pop()) if (!con[method]) con[method] = dummy; +})(typeof window === 'undefined' ? this : window); +// Using `this` for web workers while maintaining compatibility with browser +// targeted script loaders such as Browserify or Webpack where the only way to +// get to the global object is via `window`.