2

I am reading "Javascript : The good Parts" to improve my Javascript bases and knowledge. I was reading stuff about prototype and I encountered in this function :

var stooge = { ... } 
if(typeof Object.create !== 'function'){
   Object.create = function(o) {
   var F = function () {};
   F.prototype = o;
   return new F();
   };
}
var another_stooge = Object.create(stooge);

I didn't really get the meaning and the benefit of creating this function.

1 Answer 1

2

It's only a shim for the standard Object.create function which isn't available in some browsers (yes, you guessed which one).

Note that it's not complete : it doesn't do everything that is done by Object.create but it's probably enough for the author.

As for why the author wanted to use Object.create instead of a explicit prototype based OOP, it's probably because it's a little simpler.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.