{"id":1881,"date":"2013-08-26T03:17:01","date_gmt":"2013-08-26T03:17:01","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=1881"},"modified":"2013-08-26T03:17:01","modified_gmt":"2013-08-26T03:17:01","slug":"fixing-the-error-typeerror-undefined-is-not-a-function-evaluating-globalscopeconsolelog-bindglobalscopeconsole","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/fixing-the-error-typeerror-undefined-is-not-a-function-evaluating-globalscopeconsolelog-bindglobalscopeconsole\/","title":{"rendered":"Fixing the error &#8220;TypeError: &#8216;undefined&#8217; is not a function (evaluating &#8216;globalScope[&#8216;console&#8217;][&#8216;log&#8217;].bind(globalScope[&#8216;console&#8217;])&#8217;)&#8221;"},"content":{"rendered":"<p>Some libraries, like PDF.js, initialize their own logging function, which wraps console.log<sup><a href=\"#footnote_0_1881\" id=\"identifier_0_1881\" class=\"footnote-link footnote-identifier-link\" title=\"https:\/\/github.com\/thoughtbot\/capybara-webkit\/issues\/459\">1<\/a><\/sup>. If this runs in a context where function.bind does not exist, you&#8217;ll get the following error:<\/p>\n<pre>TypeError: 'undefined' is not a function \n(evaluating 'globalScope['console']['log'].\nbind(globalScope['console'])')<\/pre>\n<p>Fixing this is actually quite simple- Mozilla provides a replacement function<sup><a href=\"#footnote_1_1881\" id=\"identifier_1_1881\" class=\"footnote-link footnote-identifier-link\" title=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Function\/bind\">2<\/a><\/sup> you can drop-in (not surprising, considering how close the behavior of bind is to call and apply).<\/p>\n<p>Simply drop this code in, and you should be good to go for any environment.<\/p>\n<pre lang=\"Javascript\">if (!Function.prototype.bind) {\n  Function.prototype.bind = function (oThis) {\n    if (typeof this !== \"function\") {\n      \/\/ closest thing possible to the ECMAScript 5 internal IsCallable function\n      throw new TypeError(\n        \"Function.prototype.bind - what is trying to be bound is not callable\");\n    }\n\n    var aArgs = Array.prototype.slice.call(arguments, 1), \n        fToBind = this, \n        fNOP = function () {},\n        fBound = function () {\n          return fToBind.apply(this instanceof fNOP &amp;&amp; oThis\n            ? this\n            : oThis,\n            aArgs.concat(Array.prototype.slice.call(arguments)));\n        };\n\n    fNOP.prototype = this.prototype;\n    fBound.prototype = new fNOP();\n\n    return fBound;\n  };\n}<\/pre>\n<ol class=\"footnotes\"><li id=\"footnote_0_1881\" class=\"footnote\">https:\/\/github.com\/thoughtbot\/capybara-webkit\/issues\/459<span class=\"footnote-back-link-wrapper\"> [<a href=\"#identifier_0_1881\" class=\"footnote-link footnote-back-link\">&#8617;<\/a>]<\/span><\/li><li id=\"footnote_1_1881\" class=\"footnote\">https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Function\/bind<span class=\"footnote-back-link-wrapper\"> [<a href=\"#identifier_1_1881\" class=\"footnote-link footnote-back-link\">&#8617;<\/a>]<\/span><\/li><\/ol>","protected":false},"excerpt":{"rendered":"<p>Some libraries, like PDF.js, initialize their own logging function, which wraps console.log1. If this runs in a context where function.bind does not exist, you&#8217;ll get the following error: TypeError: &#8216;undefined&#8217; is not a function (evaluating &#8216;globalScope[&#8216;console&#8217;][&#8216;log&#8217;]. bind(globalScope[&#8216;console&#8217;])&#8217;) Fixing this is actually quite simple- Mozilla provides a replacement function2 you can drop-in (not surprising, considering how &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/fixing-the-error-typeerror-undefined-is-not-a-function-evaluating-globalscopeconsolelog-bindglobalscopeconsole\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Fixing the error &#8220;TypeError: &#8216;undefined&#8217; is not a function (evaluating &#8216;globalScope[&#8216;console&#8217;][&#8216;log&#8217;].bind(globalScope[&#8216;console&#8217;])&#8217;)&#8221;&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[13],"tags":[302,418,426,591],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/1881"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=1881"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/1881\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=1881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=1881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=1881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}