2 ms·
What do you mean by "If you don't use new, you can compose an object in multiple layers"? If you want to compose objects the correct way using prototypes, then
by sktrdie 15y ago
What do you mean by "If you don't use new, you can compose an object in multiple layers"?
If you want to compose objects the correct way using prototypes, then you need to use new at some level. If you don't use it, then you're re-allocating the entire object's properties and methods every time you need to use it.
You can do it as Crockford does with his "beget object" abstraction: http://javascript.crockford.com/prototypal.html http://javascript.crockford.com/prototypal.html
But you still need to use "new".
And personally, I'm not that convinced about promoting these sorts of abstractions as Crockford does. It's just really small syntax sugar around "new" and it's totally subjective.
So most of the time I simply feel more comfortable using "new".
- MatthewPhillips 15y agoYou can use Object.create and suffer not at all.