Search code examples
javascriptoopprototype

What is the original definition of Object.create?


function Object.create(o) {
     function F() {} 
     F.prototype = o;
     return new F(); 
}

I assume this is equivalent to the current ES6 implementation of Object.create.

  • What was the version before (it clearly changed since the new keyword didn't exist)? The original one. This is a factual question on the history of Javascript, that can be answered, I don't understand why the previous was deleted, so I'm clarifying it.
  • Is the definition without new equivalent to the one with it?
  • If it changed, were there any others (by the Good Parts author or officially)? e.g. ES5, if it is not equivalent to ES6.

Solution

  • What was the version before (it clearly changed since the new keyword didn't exist)?

    There wasn't one. new has always existed in JavaScript.

    Is the definition without new equivalent to the one with it?

    Until Object.create was added to the standard library in ES5, there wasn't any version without new. The standard version creates an object with the given prototype directly, rather than having to do it via a constructor call, but the result is the same other than no unnecessary constructor function is created.

    If it changed, were there any others (by the Good Parts author or officially)? e.g. ES5, if it is not equivalent to ES6.

    It didn't change. The standard version was added in ES5 (not ES2015/ES6) and hasn't changed substantively since. (The text of the spec has changed because the spec as a whole has changed a fair bit since then, but the fundamental steps taken and the result are the same.)