Skip to content Skip to sidebar Skip to footer

How To Get Object's [[defaultvalue]]

according to ecma262-3 8.6.2.6 [DefaultValue] http://bclary.com/2004/11/07/#a-8.6.2.6 now i want to get the [[DefaultValue]] of [ ] so according to ecma,like this: When the [[Def

Solution 1:

[[DefaultValue]] called on array object eventually gets to (and calls) array object's toString method. That method is essentially an Array.prototype.toString which is the same as calling Array.prototype.join on an array object (see 15.4.4.2). So toString on an empty array object returns empty string ("") which is a primitive value and is therefore returned from [[DefaultValue]] internal method.

So [[DefaultValue]] of array is an empty string — ifArray.prototype.string is not overwritten/shadowed, and ifArray.prototype.valueOf is not overwritten/shadowed.

[]+''; // ""Array.prototype.toString = function(){return1};
[]+''; // "1"Array.prototype.valueOf = function(){return2};
[]+''; // "2"

Post a Comment for "How To Get Object's [[defaultvalue]]"