javascript - Why doesn't MDN's `Object.create` polyfill set `prototype.constructor`? -


considering mdn's object.create polyfill:

if (typeof object.create != 'function') {   (function () {     var f = function () {};     object.create = function (o) {       if (arguments.length > 1) { throw error('second argument not supported');}       if (o === null) { throw error('cannot set null [[prototype]]');}       if (typeof o != 'object') { throw typeerror('argument must object');}       f.prototype = o;       return new f();     };   })(); } 

focusing particularly on these 2 lines:

f.prototype = o; return new f(); 

i wondering, why isn't appropriate set f.prototype.constructor = f;?

f.prototype = o; f.prototype.constructor = f;  // why not? return new f(); 

i wondering, why isn't appropriate set f.prototype.constructor = f;?

f temporary function, , seems intentional there no way reference outside object.create.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -