Rewiring the JavaScript Console in CodePen(joshbassett.info)
joshbassett.info
Rewiring the JavaScript Console in CodePen
http://joshbassett.info/2014/rewiring-the-javascript-console-in-codepen/
2 comments
You're mostly right.
The console var is assigned the result of an immediately-invoked anonymous function (http://benalman.com/news/2010/11/immediately-invoked-functio...).
The result of this function is an object which contains the console functions (log, warn, error, etc). Moreover, these functions only exist inside the scope of the anonymous function, so the only way to access them is through the returned object. This prevents the global namespace from being polluted.
So when you call console.log('hello'), you're applying one of those functions in the object returned by the anonymous function.
The console var is assigned the result of an immediately-invoked anonymous function (http://benalman.com/news/2010/11/immediately-invoked-functio...).
The result of this function is an object which contains the console functions (log, warn, error, etc). Moreover, these functions only exist inside the scope of the anonymous function, so the only way to access them is through the returned object. This prevents the global namespace from being polluted.
So when you call console.log('hello'), you're applying one of those functions in the object returned by the anonymous function.
Wow!
Once more many thanks for your time and effort. It is much appreciated. You are a Javascript GOD :-)
Cheers PK
Cheers PK
cheers PK