Oh. Never thought if that...

When i implement constructors that are lists somehow, i do this :

function Constructor( array ) {
    Array.prototype.splice.apply( this, [ 0, 0 ].concat( array ) );
}
Constructor.prototype = Object.create( Array.prototype );

But i don't get the same behavior with the length...

But doing :

function Constructor( array ) {
    array.__proto__ = Constructor.prototype;
    return array;
}

Would fix it... too bad it doesn't work in all browsers.
On Jul 20, 2011 1:50 PM, "Pete Otaqui" <[email protected]> wrote:
> This isn't really to do with arrays, but does demonstrate that you can't
> change the .prototype of an "instance" ...
>
> http://jsbin.com/onomic/4/edit
>
>
>
> On 20 July 2011 12:10, Xavier MONTILLET <[email protected]> wrote:
>
>> I didn't get your last point with Array and Date...
>> On Jul 20, 2011 12:48 PM, "Lasse Reichstein" <[email protected]>
>> wrote:
>> > On Tue, Jul 19, 2011 at 3:44 AM, RobG <[email protected]> wrote:
>> >
>> >>
>> >> Not really worth the effort. __proto__ is deprecated and shouldn't be
>> >> used for anything:
>> >> <URL:
>> >>
>>
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/proto
>> >> >
>> >
>> >
>> > I guess people will stop using it when there is a replacement that
fills
>> the
>> > niche.
>> > Currently, this is the only way to change the prototype of existing
>> objects
>> > (which is probably rarely the right thing to do), and the only way to
>> make a
>> > custom prototype chain on, e.g., Date or Array objects (Object.create
>> > doesn't do that), which can be useful.
>> >
>> > /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]
>>
>> --
>> 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]
>>
>
>
>
> --
> Pete Otaqui
> [email protected]
> +44 7949 945542
>
> --
> 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]

-- 
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