Complete Minimal Classes
brendan at mozilla.org
Fri Apr 6 21:10:14 PDT 2012
Kevin Smith wrote:
> Arbitrary prototype properties is surely to draw fire. It can be a
> foot-gun and might conflict with instance properties in the future.
> Foot gun: yes. I've shot myself in the foot with it. But I think it
> can be addressed in a way that's footgun-proof. We're going to need
> arbitrary prototype properties at some point.
Why? I mean, what built-in in ECMA-262 or a DOM spec needs non-method
data properties? Methods and accessors, yes. Constants go on the
constructor. I'm probably forgetting some bogus Java-like WebIDL binding
> Otherwise, we have to do something painful like:
> if (this instanceof MyClass)
> // construct it
> return new MyClass(...args);
Even here, you can be spoofed by calling the constructor on an
already-constructed instance. It's hard to tell 'new' from invocation by
checking facts about |this|.
More information about the es-discuss