Side-effects of some Array methods ...
brendan at mozilla.org
Fri Jun 27 13:27:06 PDT 2008
On Jun 27, 2008, at 6:51 AM, Pratap Lakshman (VJ#SDK) wrote:
> The side effect is as follows: if “this” does not have a “length”
> property, it ends up getting one; if “this” does have a length
> property, but is not an Array, that “length” property will get
True, and not just for pop -- for all generic Array methods that
> What is the rationale for this?
I don't recall a detailed rationale on this point, but the pseudo-
code is simplest without a special case that avoids creating a
'length' property if one does not exist, and it's easy to rationalize
"caveat hacker" -- if you wrote Array.prototype.pop.call(p), you
wanted to have effects on your pizza ;-). The simpler specs are a
Trying to change this now seems dicey. We don't know if any web
scripts count on this edge case. Creating length may be a requirement
because lazy pizza coders left 'length' out, knowing it would be
created, and then depended on it becoming 0 (e.g., in a < expression
-- if undefined it would become NaN and the condition would be false).
There does not seem to be any profit in taking risk by changing the
More information about the Es4-discuss