Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
64 views
in Technique[技术] by (71.8m points)

javascript - 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.
question from:https://stackoverflow.com/questions/65841758/what-is-the-original-definition-of-object-create

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...