I saw a video in which Crockford told us not to use the new
keyword. He said to use Object.create instead if I'm not mistaken. Why does he tell us not to use new
if he has used it in achieving prototypal inheritance in this article that he wrote: http://javascript.crockford.com/prototypal.html
I would expect him to use Object.create instead of new
, like this:
function object(o) {
return Object.create((function() {}).prototype = o);
}
So why is it that he still uses new
?
Object.create
not being supported across a handful of browsers, and B) that article having been written several years ago; his programming style, like most of ours, has probably changed and evolved since then. – Rob Hruska Nov 20 '11 at 16:32Object.create
if it doesn't exist. You'd only have to usenew
that one time (definingObject.create
). – Rob Hruska Nov 20 '11 at 16:40(function() {}).prototype =
part of it has no effect on your code. You'll get the same result if you doreturn Object.create( o );
– RightSaidFred Nov 20 '11 at 17:41