Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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