From: Thomas 'PointedEars' Lahn on
kangax wrote:

> Thomas 'PointedEars' Lahn wrote:
>> kangax wrote:
>>> Thomas 'PointedEars' Lahn wrote:
>>>> kangax wrote:
>>>>> Are you sure you haven't missed anything?
>>>>>
>>>>> "I would like to create own Object that would behave similar to Array
>>>>> Object, but would have defined some methods that are not in current
>>>>> ^^^^^^^^^^^^^^
>>>>> Array implementation. It need to not touch .prototype of an Array, so
>>>>> it ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>>>> should work like this"
>>>> So the thread has drifted a bit. Your approach touches ".prototype of
>>>> an
>>>> Array", too. That you are using `__proto__' to refer to said object
>>>> instead, does not change that.
>>> Doesn't OP example make it clear what was meant by "touches"? If I
>>> understood it right, the snippet with __proto__ setting doesn't "touch"
>>> `Array.prototype`.
>>
>> But the OP did not say "not use Array.prototype" to begin with; they
>> said:
>
> Of course he did.

Not in what you quoted.

> You just seem to have missed it again.

Or maybe I understood the OP differently?

> Look at the second comment of OP's example.

You did not quote that; Richard did, and it is hardly relevant.

> var a = [2,4,6];
> a.someAddedFunction(); // error - no Array .prototype extending
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

That is still not "Array.prototype". Look closer.

> Now look a bit further down:
>
> var c = new SuperArray([2,4,6]);
> [...]
> c.someAddedFunction(); // calls function
> ^^^^^^^^^^^^^^
>
> How more clear should it be?

"Array.prototype", but that would still be ambiguous (AISB).

>> "not touch .prototype of an Array". And even if we assumed that
>> ".prototype of an Array" is meant as "Array.prototype", there is still
>> ambiguity as to what that is supposed to mean:
>>
>> a) a specific property accessor
>> b) the object referred to by the value that the accessed property stores
>>
>> It stands to reason that "not touch .prototype of an Array" or "not touch
>> Array.prototype" means (b), because the OP does not want to add
>> (enumerable)
>> properties to that object (see for-in). And your suggestion of using
>> `[].__proto__' instead of `Array.prototype' in the source code does not
>> help with that because `[].__proto__ === Array.prototype' where
>> `__proto__' is
>
> The fact that `[].__proto__` and `Array.prototype` reference same object
> is irrelevant here.

It is not.

> The idea is to make sure `[]`'s [[Prototype]]
> references another object (i.e. inject that object into a scope chain of
> `[]`).

And thereby you overwrite the ".prototype of the Array" despite the OPs
requirement that it not be "touched".

> Changing `Array.prototype` would, obviously, change what
> `Array.prototype` references, not what `[]`'s [[Prototype]] references.

This is the same in green. [psf 4.5]

| 15.4.2.2 new Array(len)
|
| The [[Prototype]] property of the newly constructed object is set to the
| original Array prototype object, the one that is the initial value of
| Array.prototype (section 15.4.3.1). [...]

| 11.1.4 Array Initialiser
|
| [...]
| The production ArrayLiteral : [ Elision_opt ] is evaluated as follows:
|
| 1. Create a new array as if by the expression new Array().
|
| [...]
| The production ArrayLiteral : [ ElementList ] is evaluated as follows:
|
| 1. Evaluate ElementList.
| 2. Return Result(1).
|
| The production ArrayLiteral : [ ElementList , Elision_opt ] is evaluated
| as follows:
|
| 1. Evaluate ElementList.
| [...]
|
| The production ElementList : Elision_opt AssignmentExpression is evaluated
| as follows:
|
| 1. Create a new array as if by the expression new Array().
| [...]

> I still don't see your point here.

Read again. The OP very likely wants to avoid having an enumerable property
on the prototype object. Very likely they could not care less how the
prototype object is _not_ accessed.

>> supported. In fact, replacing the prototype object like you did
>> decreases runtime efficiency; maybe negligibly, but IMHO needlessly.
>
> You mean now that we have one more object in prototype chain? Sure it
> does, but, as you said, this is very likely so negligible that there's
> no need to worry about it.

One does if it does not satisfy the requirement of not modifying the
prototype to begin with. The was a purpose in that requirement that
you have ignored.


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
From: Dmitry A. Soshnikov on
On Oct 28, 11:56 pm, Thomas 'PointedEars' Lahn <PointedE...(a)web.de>
wrote:

>[...]
>> error - no Array .prototype extending
> >                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> That is still not "Array.prototype".  Look closer.
>

I hope you don't mean "there's a space before dot" in
"Array .prototype" vs. "Array.prototype"? :D If it's - i suggest you
to decrees you pathos ;)

> [...]
> > How more clear should it be?
>
> "Array.prototype"
>

ah, come on :) it's sort of joke or I missed something? ;)


> [...]
> >     The idea is to make sure `[]`'s [[Prototype]]
> > references another object (i.e. inject that object into a scope chain of
> > `[]`).
>
> And thereby you overwrite the ".prototype of the Array" despite the OPs
> requirement that it not be "touched".
>

Excuse me, do you really don't understand what OP have asked? Or it's
again kind of privileged humor that I can't get in? ;)

> > Changing `Array.prototype` would, obviously, change what
> > `Array.prototype` references, not what `[]`'s [[Prototype]] references.
>
> This is the same in green. [psf 4.5]
>

Changing [].[[Prototype]] as modifying - sure will affect on original
Array.prototype, but here the talk about changing in meaning of full
changing, where object on which Array.prototype points will not be
touched.

>
> Read again.  The OP very likely wants to avoid having an enumerable property
> on the prototype object.  Very likely they could not care less how the
> prototype object is _not_ accessed.
>

OP just wants do not touch object on with points Array.prototype
('cause someone whom he believes as authority recommended that) - as
he afraid of for-in loops for ordinary arrays. He just want to create
own extension and kangax and Richard give such examples, though, OP
still should "afraid" of for-in loops for that extended object, but
not for the ordinary arrays => goal is reached. What exactly you don't
understand?
From: kangax on
Thomas 'PointedEars' Lahn wrote:
> kangax wrote:
>
>> Thomas 'PointedEars' Lahn wrote:
>>> kangax wrote:
>>>> Thomas 'PointedEars' Lahn wrote:
>>>>> kangax wrote:
>>>>>> Are you sure you haven't missed anything?
>>>>>>
>>>>>> "I would like to create own Object that would behave similar to Array
>>>>>> Object, but would have defined some methods that are not in current
>>>>>> ^^^^^^^^^^^^^^
>>>>>> Array implementation. It need to not touch .prototype of an Array, so
>>>>>> it ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>>>>> should work like this"
>>>>> So the thread has drifted a bit. Your approach touches ".prototype of
>>>>> an
>>>>> Array", too. That you are using `__proto__' to refer to said object
>>>>> instead, does not change that.
>>>> Doesn't OP example make it clear what was meant by "touches"? If I
>>>> understood it right, the snippet with __proto__ setting doesn't "touch"
>>>> `Array.prototype`.
>>> But the OP did not say "not use Array.prototype" to begin with; they
>>> said:
>> Of course he did.
>
> Not in what you quoted.
>
>> You just seem to have missed it again.
>
> Or maybe I understood the OP differently?

Ok.

>
>> Look at the second comment of OP's example.
>
> You did not quote that; Richard did, and it is hardly relevant.

Should I quote specific lines every time? Are you not able to understand
the issue as a whole? Everyone seemed to have understood OP identically
(more or less), except you.

Think outside the box ;)

>
>> var a = [2,4,6];
>> a.someAddedFunction(); // error - no Array .prototype extending
>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> That is still not "Array.prototype". Look closer.

You're joking, right? :)

>
>> Now look a bit further down:
>>
>> var c = new SuperArray([2,4,6]);
>> [...]
>> c.someAddedFunction(); // calls function
>> ^^^^^^^^^^^^^^
>>
>> How more clear should it be?
>
> "Array.prototype", but that would still be ambiguous (AISB).

Oh, come on.

[...]

>> The idea is to make sure `[]`'s [[Prototype]]
>> references another object (i.e. inject that object into a scope chain of
>> `[]`).
>
> And thereby you overwrite the ".prototype of the Array" despite the OPs
> requirement that it not be "touched".

Overwrite it? Where?

Let's look at a snippet again:

var augment = (function(){
var mixin = {
last: function() {
return this[this.length-1];
},
__proto__: Array.prototype
};
return function(object) {
object.__proto__ = mixin;
return object;
};
})();

var arr = augment([1,2,3]);

Please show me at which point is `Array.prototype` "overwritten" (or, to
be specific � at which point does `Array.prototype` reference object
different than the one it originally references and/or at which point do
the properties of that object get modified)?

>
>> Changing `Array.prototype` would, obviously, change what
>> `Array.prototype` references, not what `[]`'s [[Prototype]] references.
>
> This is the same in green. [psf 4.5]
>
> | 15.4.2.2 new Array(len)
> |
> | The [[Prototype]] property of the newly constructed object is set to the
> | original Array prototype object, the one that is the initial value of
> | Array.prototype (section 15.4.3.1). [...]
>
> | 11.1.4 Array Initialiser
> |
> | [...]
> | The production ArrayLiteral : [ Elision_opt ] is evaluated as follows:
> |
> | 1. Create a new array as if by the expression new Array().
> |
> | [...]
> | The production ArrayLiteral : [ ElementList ] is evaluated as follows:
> |
> | 1. Evaluate ElementList.
> | 2. Return Result(1).
> |
> | The production ArrayLiteral : [ ElementList , Elision_opt ] is evaluated
> | as follows:
> |
> | 1. Evaluate ElementList.
> | [...]
> |
> | The production ElementList : Elision_opt AssignmentExpression is evaluated
> | as follows:
> |
> | 1. Create a new array as if by the expression new Array().
> | [...]
>
>> I still don't see your point here.
>
> Read again. The OP very likely wants to avoid having an enumerable property
> on the prototype object. Very likely they could not care less how the
> prototype object is _not_ accessed.

Of course. In fact, that enumerable property is never added to
`Array.prototype`, just as OP asked.

What is the problem here?

[...]

--
kangax
From: Jorge on
On Oct 29, 5:30 am, kangax <kan...(a)gmail.com> wrote:
> Thomas 'PointedEars' Lahn wrote:
> > kangax wrote:
>
> >> Thomas 'PointedEars' Lahn wrote:
> >>> kangax wrote:
> >>>> Thomas 'PointedEars' Lahn wrote:
> >>>>> kangax wrote:
> >>>>>> Are you sure you haven't missed anything?
>
> >>>>>> "I would like to create own Object that would behave similar to Array
> >>>>>> Object, but would have defined some methods that are not in current
> >>>>>>                                                       ^^^^^^^^^^^^^^
> >>>>>> Array implementation. It need to not touch .prototype of an Array, so
> >>>>>> it ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >>>>>> should work like this"
> >>>>> So the thread has drifted a bit.  Your approach touches ".prototype of
> >>>>> an
> >>>>> Array", too.  That you are using `__proto__' to refer to said object
> >>>>> instead, does not change that.
> >>>> Doesn't OP example make it clear what was meant by "touches"? If I
> >>>> understood it right, the snippet with __proto__ setting doesn't "touch"
> >>>> `Array.prototype`.
> >>> But the OP did not say "not use Array.prototype" to begin with; they
> >>> said:
> >> Of course he did.
>
> > Not in what you quoted.
>
> >> You just seem to have missed it again.
>
> > Or maybe I understood the OP differently?
>
> Ok.
>
>
>
> >> Look at the second comment of OP's example.
>
> > You did not quote that; Richard did, and it is hardly relevant.
>
> Should I quote specific lines every time? Are you not able to understand
> the issue as a whole? Everyone seemed to have understood OP identically
> (more or less), except you.
>
> Think outside the box ;)
>
>
>
> >> var a = [2,4,6];
> >> a.someAddedFunction();  // error - no Array .prototype extending
> >>                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> > That is still not "Array.prototype".  Look closer.
>
> You're joking, right? :)
>
>
>
> >> Now look a bit further down:
>
> >> var c = new SuperArray([2,4,6]);
> >> [...]
> >> c.someAddedFunction(); // calls function
> >>                            ^^^^^^^^^^^^^^
>
> >> How more clear should it be?
>
> > "Array.prototype", but that would still be ambiguous (AISB).
>
> Oh, come on.
>
> [...]
>
> >>     The idea is to make sure `[]`'s [[Prototype]]
> >> references another object (i.e. inject that object into a scope chain of
> >> `[]`).
>
> > And thereby you overwrite the ".prototype of the Array" despite the OPs
> > requirement that it not be "touched".
>
> Overwrite it? Where?
>
> Let's look at a snippet again:
>
> var augment = (function(){
>    var mixin = {
>      last: function() {
>        return this[this.length-1];
>      },
>      __proto__: Array.prototype
>    };
>    return function(object) {
>      object.__proto__ = mixin;
>      return object;
>    };
>
> })();
>
> var arr = augment([1,2,3]);
>
> Please show me at which point is `Array.prototype` "overwritten" (or, to
> be specific — at which point does `Array.prototype` reference object
> different than the one it originally references and/or at which point do
> the properties of that object get modified)?
>
>
>
>
>
>
>
> >> Changing `Array.prototype` would, obviously, change what
> >> `Array.prototype` references, not what `[]`'s [[Prototype]] references..
>
> > This is the same in green. [psf 4.5]
>
> > | 15.4.2.2 new Array(len)
> > |
> > | The [[Prototype]] property of the newly constructed object is set to the
> > | original Array prototype object, the one that is the initial value of
> > | Array.prototype (section 15.4.3.1). [...]
>
> > | 11.1.4 Array Initialiser
> > |
> > | [...]
> > | The production ArrayLiteral : [ Elision_opt ] is evaluated as follows:
> > |
> > | 1. Create a new array as if by the expression new Array().
> > |
> > | [...]
> > | The production ArrayLiteral : [ ElementList ] is evaluated as follows:
> > |
> > | 1. Evaluate ElementList.
> > | 2. Return Result(1).
> > |
> > | The production ArrayLiteral : [ ElementList , Elision_opt ] is evaluated
> > | as follows:
> > |
> > | 1. Evaluate ElementList.
> > | [...]
> > |
> > | The production ElementList : Elision_opt AssignmentExpression is evaluated
> > | as follows:
> > |
> > | 1. Create a new array as if by the expression new Array().
> > | [...]
>
> >> I still don't see your point here.
> (...)

I bet he's trying hard not to say that it's the instance's
original .__proto__ what should go inside __proto__ in the 'mixin',
instead of assuming that it was === Array.prototype.
--
Jorge.
From: Thomas 'PointedEars' Lahn on
kangax wrote:

> Thomas 'PointedEars' Lahn wrote:
>> kangax wrote:
>>> Thomas 'PointedEars' Lahn wrote:
>>>> kangax wrote:
>>>>> Thomas 'PointedEars' Lahn wrote:
>>>>>> kangax wrote:
>>>>>>> Are you sure you haven't missed anything?
>>>>>>>
>>>>>>> "I would like to create own Object that would behave similar to
>>>>>>> Array Object, but would have defined some methods that are not in
>>>>>>> current
>>>>>>> ^^^^^^^^^^^^^^
>>>>>>> Array implementation. It need to not touch .prototype of an Array,
>>>>>>> so it
>>>>>>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>>>>>> should work like this"
>>>>>> So the thread has drifted a bit. Your approach touches ".prototype
>>>>>> of an
>>>>>> Array", too. That you are using `__proto__' to refer to said object
>>>>>> instead, does not change that.
>>>>> Doesn't OP example make it clear what was meant by "touches"? If I
>>>>> understood it right, the snippet with __proto__ setting doesn't
>>>>> "touch" `Array.prototype`.
>>>> But the OP did not say "not use Array.prototype" to begin with; they
>>>> said:
>>> Of course he did.
>>
>> Not in what you quoted.
>>
>>> You just seem to have missed it again.
>>
>> Or maybe I understood the OP differently?
>
> Ok.
>
>>
>>> Look at the second comment of OP's example.
>>
>> You did not quote that; Richard did, and it is hardly relevant.
>
> Should I quote specific lines every time? Are you not able to understand
> the issue as a whole? Everyone seemed to have understood OP identically
> (more or less), except you.

They did not. In any case:

The fact that an opinion has been widely held is no evidence whatever that
it is not utterly absurd; indeed in view of the silliness of the majority
of mankind, a widespread belief is more likely to be foolish than
sensible.
-- Bertrand Russell (1872-1970 CE)

> Think outside the box ;)

The box that you do not want to see is that "not touch the .prototype of an
Array" was very likely a figure of speech to say "not augment the prototype
object of an Array instance."

>>> var a = [2,4,6];
>>> a.someAddedFunction(); // error - no Array .prototype extending
>>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>
>> That is still not "Array.prototype". Look closer.
>
> You're joking, right? :)

I do not.

>>> Now look a bit further down:
>>>
>>> var c = new SuperArray([2,4,6]);
>>> [...]
>>> c.someAddedFunction(); // calls function
>>> ^^^^^^^^^^^^^^
>>>
>>> How more clear should it be?
>>
>> "Array.prototype", but that would still be ambiguous (AISB).
>
> Oh, come on.

Is that supposed to be an argument?

>>> The idea is to make sure `[]`'s [[Prototype]]
>>> references another object (i.e. inject that object into a scope chain of
>>> `[]`).
>>
>> And thereby you overwrite the ".prototype of the Array" despite the OPs
>> requirement that it not be "touched".
>
> Overwrite it? Where?
>
> Let's look at a snippet again:
>
> var augment = (function(){
> var mixin = {
> last: function() {
> return this[this.length-1];
> },
> __proto__: Array.prototype
> };
> return function(object) {
> object.__proto__ = mixin;
> return object;
> };
> })();
>
> var arr = augment([1,2,3]);

That is _not_ the code in question. The code in question has been commented
on first in <news:6582835.2qOKlZ2vcF(a)PointedEars.de>, and posted by you in
<news:uq6dnerJAYtGunrXnZ2dnUVZ_u6dnZ2d(a)giganews.com>.

In any case, both approaches fail to address the requirement of "not
touch[ing] the .prototype of an Array". The resulting Array instance will
inherit enumerable properties that show up in for-in iteration.


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann