On Mon, Oct 24, 2011 at 9:05 PM, Bemi Faison <[email protected]> wrote:
> Fair enough. I meant using Object.create() on the constructor function
> itself - not an object prototype.
> I don't consider using the new statement to be a hack. In light of the
> recent ES5 specification it could be considered a deprecated statement. To
> be sure, the shim needed for Object.create to work on IE uses the new
> statement itself... so it seems we're arguing style over substance.

It's not the usage of the "new" operator that's the problem, but using
it on the constructor function.
The constructor function and its prototype property represent the
abstract type.
When you write "new MyClass()", you create and initialize an instance
of the abstract type.
This is an object of a categorically different kind than the
constructor/prototype.
When you start using that object as a prototype of another
constructor, you are mixing abstraction levels.
That's why people oppose doing "SubConstructor.prototype = new
SuperConstructor".
The properties of a MyClass *instance* doesn't necessarily make sense
on the subclass, and they don't
make sense when the same property is inherited by all subclass instances.

When you write "Object.create(MyClass.prototype)", you just create an
object inheriting from the prototype. It's not initialized by the
MyClass constructor, it just inherits the methods of the abstract
MyClass type.
Using that as the prototype of a new type keeps the abstraction level.

/L

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to