H
Howard Jess
All --
I'm trying to solve a problem for which I think the solution will be
to *cheat*; but I don't mind doing so for this case. The background is:
Given an object constructor, and an instance
SampleObj = function() {
this.prop = 1;
}
obj = new SampleObj();
obj has one enumerable property: 'prop'; and several builtin,
non-enumerable properties as well: 'toString', 'hasOwnProperty',
'propertyIsEnumerable', etc. If I redefined any of those, e.g:
SampleObj.prototype.toString = function() {return '[SampleObj]'};
then obj still has only one enumerable property; the redefinition of
toString doesn't affect its "DontEnum"-ness.
I'd like to be able to create such a property from JavaScript. In
particular, in older versions of Safari, some of those required properties
aren't implemented (hasOwnProperty, isPrototypeOf, propertyIsEnumerable,
& toLocaleString). If I define them myself:
Object.prototype.toLocaleString = Object.prototype.toString;
[etc.]
then they are enumerable, which causes problems for code like
for (var prop in obj) ...
I'll get a different set of enumerated properties in Safari than in (e.g.)
Mozilla; and have to specifically check for those that I defined myself,
to make code work appropriately on each browser. This gets tricky
(considering that the old Safari versions also failed to implement
toExponential, toFixed and toPrecision for Number objects).
The ability to set the DontEnum and ReadOnly attributes of object
properties would have been great; but (afaik) there is no way to do so. So
I'm looking for a "backdoor" in Safari that would allow this.
Help anyone?
Howard Jess
I'm trying to solve a problem for which I think the solution will be
to *cheat*; but I don't mind doing so for this case. The background is:
Given an object constructor, and an instance
SampleObj = function() {
this.prop = 1;
}
obj = new SampleObj();
obj has one enumerable property: 'prop'; and several builtin,
non-enumerable properties as well: 'toString', 'hasOwnProperty',
'propertyIsEnumerable', etc. If I redefined any of those, e.g:
SampleObj.prototype.toString = function() {return '[SampleObj]'};
then obj still has only one enumerable property; the redefinition of
toString doesn't affect its "DontEnum"-ness.
I'd like to be able to create such a property from JavaScript. In
particular, in older versions of Safari, some of those required properties
aren't implemented (hasOwnProperty, isPrototypeOf, propertyIsEnumerable,
& toLocaleString). If I define them myself:
Object.prototype.toLocaleString = Object.prototype.toString;
[etc.]
then they are enumerable, which causes problems for code like
for (var prop in obj) ...
I'll get a different set of enumerated properties in Safari than in (e.g.)
Mozilla; and have to specifically check for those that I defined myself,
to make code work appropriately on each browser. This gets tricky
(considering that the old Safari versions also failed to implement
toExponential, toFixed and toPrecision for Number objects).
The ability to set the DontEnum and ReadOnly attributes of object
properties would have been great; but (afaik) there is no way to do so. So
I'm looking for a "backdoor" in Safari that would allow this.
Help anyone?
Howard Jess