Closed
Bug 24233
Opened 25 years ago
Closed 25 years ago
trying to use Array as prototype doesn't increment length
Categories
(Core :: JavaScript Engine, defect, P3)
Tracking
()
VERIFIED
INVALID
People
(Reporter: martin.honnen, Assigned: mike+mozilla)
Details
I am using Array as the prototype for another constructor function but the
length of objects is not incremented as is with arrays:
function Dictionary (obj) {
for (var p in obj) {
alert(p + ': ' + this.length);
this[this.length] = obj[p];
this[p] = obj[p];
}
}
Dictionary.prototype = new Array();
var d = new Dictionary ({Netscape: 'JavaScript', Microsoft: 'JScript'});
Note that the above code works in NN4 while M12 with js1.5 fails to increment
the length property showing 0 every time.
Assignee | ||
Comment 1•25 years ago
|
||
I think this is a result of a fix we put in a while ago towards ECMA
conformance. When 'new some_function()' was executed, the JS engine used to
create a new object with the JSClass of some_function.prototype, instead of
using the default Object class.
(The JSClass is the 'internal' class of the object, and carries behavior such as
magic setters like that of the Array class.)
Currently, the result of executing 'new some_function()' is the default object
class, without any special getter or setter behavior, unless some_function is
specially implemented to return an object with a different JSClass.
Waldemar, Norris, Brendan - can you confirm?
Updated•25 years ago
|
Status: NEW → RESOLVED
Closed: 25 years ago
Resolution: --- → INVALID
Comment 2•25 years ago
|
||
I agree with Mike. ECMA 13.2.2 specifically requires that the class of a
Dictionary be "Object", so the length property of a Dictionary instance will not
get the special Array behavior. The M12/js1.5 behavior is correct, while NN4 was
broken.
Comment 3•25 years ago
|
||
The ECMA spec is the right way, because otherwise native class implementations
must cope with objects that have the "wrong" private data normally identified by
their class. Getters and setters (see http://www.mozilla.org/js/js15.html)
should take the sting out of this incompatible change, however.
/be
Comment 4•24 years ago
|
||
We are adhering ECMA spec so this bug is invalid. Marking as verified.
Status: RESOLVED → VERIFIED
You need to log in
before you can comment on or make changes to this bug.
Description
•