Crockford gives an example of an object creation function that should have been provided by JS itself in one of its Javascript conversations, available at http://developer.yahoo.com/yui/theater/
However, the YUI (3) team itself uses the “new” one, and they fulfill their recommendations (since he is the chief architect of JS Yahoo (UPDATE: he switched, but the statement was true when this answer was originally written) I understand that this particular statement is more it looks like an “academic” level that SHOULD understand that the language was designed “correctly” and not with some remnants of class-based inheritance.He (IMHO rightly) says that the path turned out to be JS conflicting based on the prototype, but with this one of the classi inheritance languages class. "
However, JS is as it is, and use the "new" one.
Here you can find its object creation function: http://javascript.crockford.com/prototypal.html
if (typeof Object.create !== 'function') { Object.create = function (o) { function F() {} F.prototype = o; return new F(); }; } newObject = Object.create(oldObject);
EDIT: Updated to use the latest version of this Crockford feature - there are three.
UPDATE June 2015: we already have Object.create(...) that all current browsers (including IE 9 and above), so there was no need to use the Crockford function.
However, it turns out that if you use Object.create , you must make sure that you do not: this function is slower than when using new Constructor() !
See http://mrale.ph/blog/2014/07/30/constructor-vs-objectcreate.html for an explanation (for the V8 engine) and see http://jsperf.com/object-create-vs-crockford -vs-jorge-vs-constructor / 62 to demonstrate performance.
Another reason not to turn to new Constructor(...) is that ES6 classes will undoubtedly see widespread adoption, even if only for the simple reason that most Javascript developers come from classes.
Also check out this article claiming Object.create : http://davidwalsh.name/javascript-objects-deconstruction
Whether you like it or not, especially in projects that you want to share with a wide range of people (in space and time, which means right or not time, other people charge you) there are more reasons to use new .
UPDATE September 2015: for myself, I started using Javascript ES 2015 for everything - using either io.js and / or Babel. I also do not use any new in my projects, except for built-in Javascript, such as new Error(...) . I prefer to use a much more powerful functional approach, I completely ignore the object system. [my-object].prototype and this completely disappeared from my projects. For a long time I was very skeptical of these ideas "because objects work very well." But after he reluctantly gave him an attempt at the start of a new project (io.js), he “clicked”, and I don’t understand why I spent two decades. Well, not quite, today JS engines and hardware are much more favorable for this style. Especially with ES 2015, I recommend giving a functional style that is completely free of any this and class (the new ES 2015 keyword or the whole concept based on using constructorFn.prototype ). This may take several weeks, but as soon as it “clicks”, I promise that you will never return - not voluntarily. It is much more convenient and powerful.