Re: array like objects

2009-12-16 Thread P T Withington
On 2009-12-15, at 23:28, Brendan Eich wrote: Something more like Self, in other words. I still wonder if we can't recover that lost form, enable prototype-based composition as Tucker wanted, and banish host objects to the ninth circle of hell, in a future edition. We can dream! :)

Re: array like objects

2009-12-15 Thread Jorge Chamorro
On 15/12/2009, at 13:51, P T Withington wrote: (...) I once had the vain hope that I could say: function MyArray () {} MyArray.prototype = []; to create my own subclasses of Array. That might have lessened the need for isArrayLike. For that, we'd need an Array.create(). It might be

Re: array like objects

2009-12-15 Thread Brendan Eich
On Dec 15, 2009, at 4:51 AM, P T Withington wrote: On 2009-12-08, at 13:10, Mike Samuel wrote: All true. And yet it is not uncommon. See the bottom of this email for a quick survey of a number of libraries' uses of the array-like concept. FWIW, Here is the (separately/simultaneously

Re: array like objects

2009-12-15 Thread Brendan Eich
On Dec 15, 2009, at 5:05 AM, Jorge Chamorro wrote: On 15/12/2009, at 13:51, P T Withington wrote: (...) I once had the vain hope that I could say: function MyArray () {} MyArray.prototype = []; to create my own subclasses of Array. That might have lessened the need for isArrayLike. For

Re: array like objects

2009-12-15 Thread Jorge Chamorro
On 15/12/2009, at 16:21, Brendan Eich wrote: On Dec 15, 2009, at 5:05 AM, Jorge Chamorro wrote: On 15/12/2009, at 13:51, P T Withington wrote: (...) I once had the vain hope that I could say: function MyArray () {} MyArray.prototype = []; to create my own subclasses of Array. That

Re: array like objects

2009-12-15 Thread Brendan Eich
On Dec 15, 2009, at 8:46 AM, Jorge Chamorro wrote: It's the same functionality provided by Object.create(), but for [] instead of {}. Ah, that helps -- thanks. This is not exactly what Tucker showed, though. Tucker is looking for a way to compose custom [[Put]] with prototype-based

Re: array like objects

2009-12-15 Thread David-Sarah Hopwood
Brendan Eich wrote: In ES specs and real implementations, internal methods and various corresponding implementation hooks are called based on [[Class]] of the directly referenced object, in contrast. In ES specs, there's no indication that [[Class]] can or should be used for internal method

Re: array like objects

2009-12-15 Thread Brendan Eich
On Dec 15, 2009, at 11:18 AM, David-Sarah Hopwood wrote: Brendan Eich wrote: In ES specs and real implementations, internal methods and various corresponding implementation hooks are called based on [[Class]] of the directly referenced object, in contrast. In ES specs, there's no

Re: array like objects

2009-12-15 Thread David-Sarah Hopwood
Brendan Eich wrote: On Dec 15, 2009, at 11:18 AM, David-Sarah Hopwood wrote: Brendan Eich wrote: In ES specs and real implementations, internal methods and various corresponding implementation hooks are called based on [[Class]] of the directly referenced object, in contrast. [...] Sorry, I

Re: array like objects

2009-12-14 Thread Mike Samuel
2009/12/13 Garrett Smith dhtmlkitc...@gmail.com: On Sun, Dec 13, 2009 at 10:31 AM, Mike Samuel mikesam...@gmail.com wrote: 2009/12/12 Garrett Smith dhtmlkitc...@gmail.com: On Sat, Dec 12, 2009 at 4:04 PM, Mark S. Miller erig...@google.com wrote: On Sat, Dec 12, 2009 at 3:38 PM, Garrett Smith

Re: array like objects

2009-12-14 Thread Garrett Smith
On Mon, Dec 14, 2009 at 9:34 AM, Mike Samuel mikesam...@gmail.com wrote: 2009/12/13 Garrett Smith dhtmlkitc...@gmail.com: On Sun, Dec 13, 2009 at 10:31 AM, Mike Samuel mikesam...@gmail.com wrote: 2009/12/12 Garrett Smith dhtmlkitc...@gmail.com: On Sat, Dec 12, 2009 at 4:04 PM, Mark S. Miller

Re: array like objects

2009-12-14 Thread Breton Slivka
On Tue, Dec 15, 2009 at 6:29 AM, Mike Samuel mikesam...@gmail.com wrote: (3) If (!1), should future EcmaScript drafts define iteration order for arrays as index order and possibly recommend to array like host objects that the define iteration order similarly. I would suggest that this change

Re: array like objects

2009-12-14 Thread Mike Samuel
2009/12/14 Breton Slivka z...@zenpsycho.com: On Tue, Dec 15, 2009 at 6:29 AM, Mike Samuel mikesam...@gmail.com wrote: (3) If (!1), should future EcmaScript drafts define iteration order for arrays as index order and possibly recommend to array like host objects that the define iteration order

Re: array like objects

2009-12-14 Thread Breton Slivka
On Tue, Dec 15, 2009 at 10:34 AM, Mike Samuel mikesam...@gmail.com wrote: 2009/12/14 Breton Slivka z...@zenpsycho.com: On Tue, Dec 15, 2009 at 6:29 AM, Mike Samuel mikesam...@gmail.com wrote: (3) If (!1), should future EcmaScript drafts define iteration order for arrays as index order and

Re: array like objects

2009-12-14 Thread Garrett Smith
On Mon, Dec 14, 2009 at 11:29 AM, Mike Samuel mikesam...@gmail.com wrote: 2009/12/14 Garrett Smith dhtmlkitc...@gmail.com: On Mon, Dec 14, 2009 at 9:34 AM, Mike Samuel mikesam...@gmail.com wrote: 2009/12/13 Garrett Smith dhtmlkitc...@gmail.com: On Sun, Dec 13, 2009 at 10:31 AM, Mike Samuel

Re: array like objects

2009-12-13 Thread Brendan Eich
On Dec 12, 2009, at 12:36 PM, Mark S. Miller wrote: On Sat, Dec 12, 2009 at 12:29 PM, Garrett Smith dhtmlkitc...@gmail.com wrote: Object.prototype.propertyIsEnumerable does not consider properties in the prototype chain. In effect, propertyIsEnumerable is a test to see if an object has *own*

RE: array like objects

2009-12-12 Thread Mike Wilson
David-Sarah Hopwood wrote: Mark S. Miller wrote: function isArrayLike(obj) { var len; return !!(obj typeof obj === 'object' 'length' in obj !({}).propertyIsEnumerable.call(obj, 'length') (len = obj.length) 0 === len); } If

Re: array like objects

2009-12-12 Thread Garrett Smith
On Fri, Dec 11, 2009 at 12:08 PM, Mike Wilson mike...@hotmail.com wrote: Mark S. Miller wrote: If we're looking for a convention that is * does not admit any legacy ES3R non-array non-host objects (to prevent false positives) No native ES objects? * does easily allow ES5 programmers to

RE: array like objects

2009-12-12 Thread Mike Wilson
Mark S. Miller wrote: On Sat, Dec 12, 2009 at 10:36 AM, Mike Samuel mikesam...@gmail.com wrote: On the String defect, we could repair that with ({}).toString.call(obj) !== '[object String]' Cons: An extra function call in the likely case Strings are arguable array-like Pros: Strings

Re: array like objects

2009-12-12 Thread Brendan Eich
On Dec 12, 2009, at 11:36 AM, Mike Wilson wrote: Mark S. Miller wrote: On Sat, Dec 12, 2009 at 10:36 AM, Mike Samuel mikesam...@gmail.com wrote: On the String defect, we could repair that with ({}).toString.call(obj) !== '[object String]' Cons: An extra function call in the likely

Re: array like objects

2009-12-12 Thread Brendan Eich
On Dec 12, 2009, at 10:36 AM, Mike Samuel wrote: 2009/12/12 Mike Wilson mike...@hotmail.com: David-Sarah Hopwood wrote: Mark S. Miller wrote: function isArrayLike(obj) { var len; return !!(obj typeof obj === 'object' 'length' in obj

Re: array like objects

2009-12-12 Thread Garrett Smith
On Sat, Dec 12, 2009 at 12:01 PM, Mark S. Miller erig...@google.com wrote: On Sat, Dec 12, 2009 at 11:21 AM, Garrett Smith dhtmlkitc...@gmail.com wrote: On Fri, Dec 11, 2009 at 12:08 PM, Mike Wilson mike...@hotmail.com wrote: Mark S. Miller wrote: If we're looking for a convention that

Re: array like objects

2009-12-12 Thread Mark S. Miller
On Sat, Dec 12, 2009 at 12:29 PM, Garrett Smith dhtmlkitc...@gmail.comwrote: Object.prototype.propertyIsEnumerable does not consider properties in the prototype chain. In effect, propertyIsEnumerable is a test to see if an object has *own* property that is also enumerable. And just when I

Re: array like objects

2009-12-12 Thread Mark S. Miller
On Sat, Dec 12, 2009 at 12:29 PM, Garrett Smith dhtmlkitc...@gmail.com wrote: Object.prototype.propertyIsEnumerable does not consider properties in the prototype chain. In effect, propertyIsEnumerable is a test to see if an object has *own* property that is also enumerable. At the end of

Re: array like objects

2009-12-12 Thread Mark S. Miller
On Sat, Dec 12, 2009 at 3:38 PM, Garrett Smith dhtmlkitc...@gmail.comwrote: On Sat, Dec 12, 2009 at 2:59 PM, Mark S. Miller erig...@google.com wrote: Are we really this stuck? Can anyone think of a reliable, portable, and fast ES3R test that tests whether a property is enumerable, whether

Re: array like objects

2009-12-12 Thread Mike Samuel
2009/12/12 Brendan Eich bren...@mozilla.com: On Dec 12, 2009, at 10:36 AM, Mike Samuel wrote: 2009/12/12 Mike Wilson mike...@hotmail.com: David-Sarah Hopwood wrote: Mark S. Miller wrote: function isArrayLike(obj) {  var len;  return !!(obj            typeof obj === 'object'          

Re: array like objects

2009-12-12 Thread Mike Samuel
2009/12/12 Garrett Smith dhtmlkitc...@gmail.com: On Fri, Dec 11, 2009 at 12:08 PM, Mike Wilson mike...@hotmail.com wrote: Mark S. Miller wrote: If we're looking for a convention that is * does not admit any legacy ES3R non-array non-host objects (to prevent false positives) No native ES

Re: array like objects

2009-12-12 Thread Garrett Smith
On Sat, Dec 12, 2009 at 4:04 PM, Mark S. Miller erig...@google.com wrote: On Sat, Dec 12, 2009 at 3:38 PM, Garrett Smith dhtmlkitc...@gmail.com wrote: On Sat, Dec 12, 2009 at 2:59 PM, Mark S. Miller erig...@google.com wrote: Are we really this stuck? Can anyone think of a reliable,

RE: array like objects

2009-12-11 Thread Mike Wilson
I think Breton mentions something important here; the desire to actually detect if something is an array or arraylike to be able to branch to different code that does completely different things for array[likes] and objects. If we just provide a better generic iteration construct then this part is

Re: array like objects

2009-12-11 Thread Mark S. Miller
On Fri, Dec 11, 2009 at 2:27 AM, Mike Wilson mike...@hotmail.com wrote: I think Breton mentions something important here; the desire to actually detect if something is an array or arraylike to be able to branch to different code that does completely different things for array[likes] and

Re: array like objects

2009-12-11 Thread Mark S. Miller
[+commonjs] On Fri, Dec 11, 2009 at 12:08 PM, Mike Wilson mike...@hotmail.com wrote: Thanks Mark, this is the right way to approach it I think. String objects will be considered array-like above which may not be desired, but either way, I think it is this type of guideline that can prove

Re: array like objects

2009-12-11 Thread David-Sarah Hopwood
Mark S. Miller wrote: On Fri, Dec 11, 2009 at 2:27 AM, Mike Wilson mike...@hotmail.com wrote: I think Breton mentions something important here; the desire to actually detect if something is an array or arraylike to be able to branch to different code that does completely different things

Re: array like objects

2009-12-08 Thread Erik Corry
2009/12/8 Mike Samuel mikesam...@gmail.com: It occurred to me after looking at the proxy strawman that it might help to nail down what array-like means in future drafts.  It isn't directly related to the proxy stuff though so I thought I'd start a separate thread. I've seen quite a bit of

Re: array like objects

2009-12-08 Thread Mike Samuel
2009/12/8 Erik Corry erik.co...@gmail.com: 2009/12/8 Mike Samuel mikesam...@gmail.com: It occurred to me after looking at the proxy strawman that it might help to nail down what array-like means in future drafts.  It isn't directly related to the proxy stuff though so I thought I'd start a

Re: array like objects

2009-12-08 Thread Juriy Zaytsev
On Dec 8, 2009, at 1:10 PM, Mike Samuel wrote: 2009/12/8 Erik Corry erik.co...@gmail.com: 2009/12/8 Mike Samuel mikesam...@gmail.com: It occurred to me after looking at the proxy strawman that it might help to nail down what array-like means in future drafts. It isn't directly related to

Re: array like objects

2009-12-08 Thread Brendan Eich
Ok, let's think about a new loop construct. Adding new syntax makes for-in a boat-anchor implementations lug around, in the best case. But realistically it will be years before developers can count on the new loop construct. And as support comes online, developers will have to choose which

Re: array like objects

2009-12-08 Thread Mike Samuel
2009/12/8 Brendan Eich bren...@mozilla.com: On Dec 8, 2009, at 10:10 AM, Mike Samuel wrote: 1) Does the object have the special semantics around .length?  This is potentially useful to know and the normal way to find out doesn't work.  Instanceof is affected by setting __proto__, yet the

Re: array like objects

2009-12-08 Thread Mike Samuel
2009/12/8 Brendan Eich bren...@mozilla.com: On Dec 8, 2009, at 11:51 AM, Erik Corry wrote: for (let i in arraylike) {   i |= 0; If this pattern catches on then we could optimize for it without changing the language. Yeah, but some day there will be only new versions in which i is numeric

Re: array like objects

2009-12-08 Thread Brendan Eich
On Dec 8, 2009, at 12:52 PM, Mike Samuel wrote: 2009/12/8 Brendan Eich bren...@mozilla.com: On Dec 8, 2009, at 11:51 AM, Erik Corry wrote: for (let i in arraylike) { i |= 0; If this pattern catches on then we could optimize for it without changing the language. Yeah, but some day there

Re: array like objects

2009-12-07 Thread Yehuda Katz
Your strawman would support: {0: strawman, length: 0} A better definition might be: o is an array like object if o[[Get]]('length') returns a Number one greater than the largest numeric property, or 0 if no numeric properties exist. Yehuda Katz Developer | Engine Yard (ph) 718.877.1325 On

RE: array like objects

2009-12-07 Thread Allen Wirfs-Brock
be used for all array-like situations. Allen From: es-discuss-boun...@mozilla.org [mailto:es-discuss-boun...@mozilla.org] On Behalf Of Yehuda Katz Sent: Monday, December 07, 2009 5:40 PM To: mikesam...@gmail.com Cc: es-discuss Subject: Re: array like objects Your strawman would support: {0

Re: array like objects

2009-12-07 Thread Mike Samuel
2009/12/7 Yehuda Katz wyc...@gmail.com: Your strawman would support: {0: strawman, length: 0} A better definition might be:    o is an array like object if o[[Get]]('length') returns a Number one greater than the largest numeric property, or 0 if no numeric properties exist. By that better

Re: array like objects

2009-12-07 Thread Breton Slivka
The one that I use is function isArrayLike(i){ return (typeof i !==string) i.length !== void (0); } It might not be perfect, but it allows me to make certain assumptions about the input that are useful enough. Keep in mind that an Array may have a length of 5, and all those values are

Re: array like objects

2009-12-07 Thread Breton Slivka
On Tue, Dec 8, 2009 at 1:29 PM, Breton Slivka z...@zenpsycho.com wrote: The one that I use is function isArrayLike(i){ return (typeof i !==string) i.length !== void (0); } It might not be perfect, but it allows me to make certain assumptions about the input that are useful enough. Keep

Re: array like objects

2009-12-07 Thread Mike Samuel
From: es-discuss-boun...@mozilla.org [mailto:es-discuss-boun...@mozilla.org] On Behalf Of Yehuda Katz Sent: Monday, December 07, 2009 5:40 PM To: mikesam...@gmail.com Cc: es-discuss Subject: Re: array like objects Your strawman would support: {0: strawman, length: 0} A better

Re: array like objects

2009-12-07 Thread Mike Samuel
2009/12/7 Breton Slivka z...@zenpsycho.com: The one that I use is function isArrayLike(i){    return (typeof i !==string) i.length !== void (0); I like that it's efficient. How about if (i !== null typeof i === 'object') { var len = i.length; var ilen = len 0; return