![]() | |
![]() |
| | Thread Tools | Display Modes |
#41
| |||
| |||
|
|
But for-in loops is also not so useful (it's slower) as for-length loops as they analyze prototype chain (for all that [push], [pop] and ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ so on properties) and make the check on any iteration such as [if (! property.isEnumerable()) continue;]. |
#42
| ||||||||||
| ||||||||||
|
|
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. |
|
You just seem to have missed it again. |
|
Look at the second comment of OP's example. |
|
var a = [2,4,6]; a.someAddedFunction(); // error - no Array .prototype extending ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
|
Now look a bit further down: var c = new SuperArray([2,4,6]); [...] c.someAddedFunction(); // calls function ^^^^^^^^^^^^^^ How more clear should it be? |
|
"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. |
|
The idea is to make sure `[]`'s [[Prototype]] references another object (i.e. inject that object into a scope chain of `[]`). |
|
Changing `Array.prototype` would, obviously, change what `Array.prototype` references, not what `[]`'s [[Prototype]] references. |
|
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. |
|
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. |
#43
| |||||
| |||||
|
|
[...] error - no Array .prototype extending * * * * * * * * * * * * * * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ That is still not "Array.prototype". *Look closer. |
If it's - i suggest you
|
[...] How more clear should it be? "Array.prototype" |
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". |

|
Changing `Array.prototype` would, obviously, change what `Array.prototype` references, not what `[]`'s [[Prototype]] references. This is the same in green. [psf 4.5] |
|
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. |
#44
| ||||||
| ||||||
|
|
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). |
|
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. |
#45
| |||
| |||
|
|
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. (...) |
#46
| |||||
| |||||
|
|
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]); |
#47
| ||||
| ||||
|
|
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 whateverthat * 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) |
Do you
|
[...] You're joking, right? ![]() I do not. |
"You do not". "No.", "They do not.", "Everybody's
|
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? |
|
[...] 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. |
) - "sorry, guys, I did't understand it correctly", you still
#48
| |||
| |||
|
|
Thomas 'PointedEars' Lahn wrote: kangax wrote: 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) [...] [...] 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. You still continue to sing your song, just because you can't say (yeah, I understand - it's hard, when you believe yourself higher than other ) - "sorry, guys, I did't understand it correctly", you stillcontinue talking about stupid "the .prototype of an Array" === "[[Prototype]] of []" [...] |
#49
| |||
| |||
|
|
Dmitry A. Soshnikov wrote: Thomas 'PointedEars' Lahn wrote: kangax wrote: 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) [...] [...] 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. You still continue to sing your song, just because you can't say (yeah, I understand - it's hard, when you believe yourself higher than other ) - "sorry, guys, I did't understand it correctly", you stillcontinue talking about stupid "the .prototype of an Array" === "[[Prototype]] of []" [...] q.e.d. PointedEars -- var bugRiddenCrashPronePieceOfJunk = ( * * navigator.userAgent.indexOf('MSIE 5') != -1 * * && navigator.userAgent.indexOf('Mac') != -1 ) *// Plone, register_function.js:16 |
don't be worry, you already lost 
) - try to discuss
).
#50
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |