Name: setOwnProperty - overrides addProperty methods on prototypes to assign a value to a specific object
Author: senocular: www.senocular.com
Date: 1899-12-31T00:00:40.600
Documentation:
Object SETOWNPROPERTY: allows you to set a property
to an object instance without interference from
prototype methods such as those added with
addProperty.
Object.setOwnProperty("property", value);
Arguments:
- property: (string) a string of the name of the property to be added/changed
- value: the value the property is to recieve
Returns:
- nothing
Example:
// simple addProperty
getHi = function(){
return "hi";
};
Object.prototype.addProperty("hi",getHi,null);
// make an object to test with
myObj = {};
trace(myObj.hi); // hi
myObj.hi = 5;
trace(myObj.hi); // hi
// ^ as a result of the added hi property on Object.prototype
myObj.setOwnProperty("hi", 5);
trace(myObj.hi); // 5
// ^ setOwnProperty bipassed the added hi property
1
2
3
4
5
6
Object.prototype.setOwnProperty = function(prop, value){
var p = this.__proto__;
this.__proto__ = null;
this[prop] = value;
this.__proto__ = p;
}