Hello I am learning JavaScript.
In regards to the below shim why did the author put var F outside of the anonymous function(o) and create a closure. Wouldn't var F inside of function(o) have worked also?
Thank you.
Code:if (typeof Object.create != 'function') { (function () { // why is this outside of Object.Create. var F = function () {}; Object.create = function (o) { if (arguments.length > 1) { throw Error('Second argument not supported');} if (o === null) { throw Error('Cannot set a null [[Prototype]]');} if (typeof o != 'object') { throw TypeError('Argument must be an object');} F.prototype = o; return new F; }; })(); }


Reply With Quote
Bookmarks