From: Dmitry A. Soshnikov on
OK, the new series has just begun.

"ECMA-262-5 in detail. Chapter 1. Properties and Property
Descriptors."

http://dmitrysoshnikov.com/ecmascript/es5-chapter-1-properties-and-property-descriptors/

It isn't already a translation, but the original. But, nevertheless,
additions/corrections -- technical and in English are welcome.

Dmitry.
From: Ry Nohryb on
On Apr 29, 11:27 am, "Dmitry A. Soshnikov"
<dmitry.soshni...(a)gmail.com> wrote:
> OK, the new series has just begun.
>
> "ECMA-262-5 in detail. Chapter 1. Properties and Property
> Descriptors." (...)

"Using such approach you at last can create inherited from
Array.prototype “class” with all functionality of normal arrays
including overloaded [[Get]] and [[Put]] internal methods which handle
e.g. length property."

There's still NO WAY to subclass Array in ES (neither 3 nor 5) : your
"foo" Array subclass is broken:

foo
--> [1,2,3]
foo.length
--> 3
foo[22]= 27
foo.length
--> 3

You'd be better off doing this, ISTM:

(foo= []).sum= arraySum;

For the internal get and put are not in your foo. The ONLY way to
subclass Array is using the non-standard __proto__ to insert one (or
more than one to subclass a subclass) intermediate object(s) in the
prototype chain of a true [] :

var foo= [];
foo.__proto__= { foo: "FOO" };
foo.__proto__.__proto__= Array.prototype;

foo instanceof Array
--> true

foo.foo
--> "FOO"

foo.length
--> 0

foo.push(66)
--> 1

foo[3]= 66
foo.length
--> 4

foo
--> [66, undefined, undefined, 66]

foo.length= 0
foo
--> []
--
Jorge.
From: Dmitry A. Soshnikov on
On Apr 29, 3:33 pm, Ry Nohryb <jo...(a)jorgechamorro.com> wrote:
> On Apr 29, 11:27 am, "Dmitry A. Soshnikov"
>
> <dmitry.soshni...(a)gmail.com> wrote:
> > OK, the new series has just begun.
>
> > "ECMA-262-5 in detail. Chapter 1. Properties and Property
> > Descriptors." (...)
>
> "Using such approach you at last can create inherited from
> Array.prototype “class” with all functionality of normal arrays
> including overloaded [[Get]] and [[Put]] internal methods which handle
> e.g. length property."
>
> There's still NO WAY to subclass Array in ES (neither 3 nor 5) : your
> "foo" Array subclass is broken:
>
> foo
> --> [1,2,3]
> foo.length
> --> 3
> foo[22]= 27
> foo.length
> --> 3
>
> You'd be better off doing this, ISTM:
>
> (foo= []).sum= arraySum;
>
> For the internal get and put are not in your foo. The ONLY way to
> subclass Array is using the non-standard __proto__ to insert one (or
> more than one to subclass a subclass) intermediate object(s) in the
> prototype chain of a true [] :
>
> var foo= [];
> foo.__proto__= { foo: "FOO" };
> foo.__proto__.__proto__= Array.prototype;
>
> foo instanceof Array
> --> true
>
> foo.foo
> --> "FOO"
>
> foo.length
> --> 0
>
> foo.push(66)
> --> 1
>
> foo[3]= 66
> foo.length
> --> 4
>
> foo
> --> [66, undefined, undefined, 66]
>
> foo.length= 0
> foo
> --> []

Absolutely correct. I knew that for ES3 of course, but have hastened
with it for ES5. Just thought which more interesting example to use
and used that. And forgot about that only objects with
"Array" [[Class]] has overloaded internal methods related to arrays
stuff (15.4.5.1 in ES5).

Thanks, fixed. I also added your example.

Dmitry.
From: Ry Nohryb on
On Apr 29, 2:08 pm, "Dmitry A. Soshnikov" <dmitry.soshni...(a)gmail.com>
wrote:
>
> Thanks, fixed. I also added your example.

You're welcome Dmitry.

"And unfortunately, in contrast with __proto__ extension of some ES3
implementation, ES5 does not provide ability for setting an object’s
prototype."

I find this phrase a bit nonsensical. The __proto__ wasn't part of ES
before (ES3) and still isn't (ES5). It was provided by some
implementations, and it's still being provided by these
implementations. AFAIK.
--
Jorge.
From: Ry Nohryb on
On Apr 29, 2:08 pm, "Dmitry A. Soshnikov" <dmitry.soshni...(a)gmail.com>
wrote:
> On Apr 29, 3:33 pm, Ry Nohryb <jo...(a)jorgechamorro.com> wrote:
> (... ) And forgot about that only objects with
> "Array" [[Class]] has overloaded internal methods related to arrays
> stuff (15.4.5.1 in ES5).

Yeah. Object.create() returns an {}. To subclass [] we'd need an
Array.create(). I told this once to Brendan Eich @ es-discus, but
unfortunately I couldn't understand his too-complicated-for-me
response... :-)

https://mail.mozilla.org/pipermail/es-discuss/2009-December/010425.html
--
Jorge.