Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

deproto.as

Name: deproto() - removes prototype reference in object
Author: senocular: www.senocular.com
Date: 1899-12-31T00:14:34.400
Documentation:
Object DEPROTO: takes prototype reference away from an object. In
doing this, only instance specific properties/functions will be
'existant' within that object.  Doing this to internal objects such
as arrays will void them of their object type and make them generic.
And if you act now we'll throw in a free Object REPROTO: restores
the prototype reference of a deprotoed object (has to be used in the
form reproto(objectToRestore)).

[reproto]
Arguments:
- obj: the object instance whos prototype has been removed by deproto which you want to restore

Application:
- good for making objects where you dont have to worry about them contracting the disease of
the ever so contagious Object.prototype and its methods.  deprotoed objects are contain and
know only what you specifically give them.

Object.prototype.y = "y";
Object.prototype.z = "z";
customObj = function(a,b){
	this.a = a;
	this.b = b;
	this.deproto();
}

objInstance = new customObj("a","b");
for (props in objInstance) trace(props +": "+ objInstance[props]);
// outputs:
a: a
b: b


Example:
Animal = function(){}
Animal.prototype.head = "large";
Animal.prototype.tail = "short";

spot = new Animal();
spot.kind = "dog";

for (props in spot) trace(props +": "+ spot[props]);
spot.deproto();
trace("---deprotoed spot---");
for (props in spot) trace(props +": "+ spot[props]);
reproto(spot);
trace("---reprotoed spot---");
for (props in spot) trace(props +": "+ spot[props]);

// outputs:
reproto: [type Function]
deproto: [type Function]
tail: short
head: large
kind: dog
---deprotoed spot---
kind: dog
---reprotoed spot---
reproto: [type Function]
deproto: [type Function]
tail: short
head: large
kind: dog

1
2
3
4
5
6
7
Object.prototype.deproto = function(){
	this.__proto__ = null;
}

Object.prototype.reproto = function(obj){
	obj.__proto__ = obj.constructor.prototype;
}