And, one thing is still very important, the object really does not
have the constructor property

>>> function a(){}
>>> b=new a
Object
>>> b.constructor==a
true
>>> b.hasOwnProperty("constructor")
false
>>> b.__proto__.constructor==a
true
>>> b.__proto__.constructor
a()
and I really think the "constructor" property is no use at
all............. No one relys on the constructor property to get the
real constructor function...


On Sep 9, 8:29 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Thanks very much, and I think this constructor property is really not
> very reliable, such as:
> function a(){}
> a.prototype={b:123}
> b=new a
> b.constructor==Object //true
> and:
> function a(){}
> a.prototype=new String("aaa");
> b=new a;
> b.constructor==String
> you can change the constructor before or after you constructing your
> object, not very reliable, and futhermore:
> function a(){return new String("aaa")}
> a.prototype.a=123;
> b=new a
> b.a //undefined
> b //String object "aaa"
> If you return an object in your constructor function, and all the
> created object will be ignored by the JavaScript interpreter. And
> except for get the real constructor function from the object's
> constructor property, I can see no reason to redefine it, it has no
> other usage at all. It can not change the prototype chain, it just
> define who is the constructor function and does not very reliable
>
> On Sep 9, 1:13 am, Robert Kati  <[EMAIL PROTECTED]> wrote:
>
>
>
> > When you create a new function it has a "prototype" property, which
> > has a "constructor" property which refer to the created function:
>
> > function F(){};
> > F.prototype.constructor === F  =>  true
>
> > So you will be able to get the class of an instance:
>
> > var obj = new F;
> > obj.constructor === F  => true
>
> > When we redefine the "prototype" property of an function, their
> > "constructor" must be redefined too:
>
> > function G(){};
> > G.prototype = new F;
> > var obj = new G;
> > obj.constructor === F  // true !!not good!!
> > G.prototype.constructor = G;
> > obj.constructor === G  // true - ok
>
> > The special "__proto__" property is available only on Gecko engines,
> > and it is used to redefine the prototype chain... so it's not cross-
> > browser solution... my module for OOP in JS use this optimization too,
> > but it's not strictly necessary...
>
> > I hope this answer will help you,
>
> > Robert
>
> > On Sep 8, 4:12 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
> > > I have seen the new inheritance code from Alex in 1.60 rc0, and I have
> > > a question: I believe the following two lines code are no use at all
> > >     method.prototype.constructor = method;
> > >     subclass.prototype.constructor = subclass;
> > > constructor property is no use at all, the usage property is __proto__
> > > and you can not alter it in IE, is there something I do not know about
> > > constructor property which is also very important?- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to