Lasse Reichstein wrote:
> Bemi Faison wrote:
> 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.
... which is why if you do use a constructor in this fashion, you
should always separate out the initialization into a separately-called
function, one which is not called in this inheritance scenario.
> 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.
I simply have never been quite certain when I can depend upon
Object.create being present and functioning correctly. And I'm wary
of shims which can never do what the original is supposed to do.
Which is why I still mostly use:
var F = function() {};
F.prototype = Parent.prototype;
Child.prototype = new F();
This is perhaps less obvious than Object.create, but it's a well-known
pattern, and I'm quite certain that the environments I care about
support it., especially as my current project has to support IE7, and
I would like it to support older versions of FF as well.
I know there are many `Object.create` shims out there, but some of the
properties that can be defined seem impossible to shim. Would there
be any way to shim `ennumerable`?
-- Scott
--
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]