Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function addDefaultStyleToProtoChain(chain):Object {
- // If there's a defaultFactory for this style sheet,
- // then add the object it produces to the chain.
- if (defaultFactory != null)
- {
- var originalChain:Object = chain;
- // from here on...
- defaultFactory.prototype = chain;
- chain = new defaultFactory();
- defaultFactory.prototype = null;
- }
- return chain;
- }
- var o:Object = new defaultFactory();
- trace(o) // {fontFamily:Arial, color:blue};
- trace(chain) // {color:red, fontWeight:bold}
- defaultFactory.prototype = chain;
- chain = new defaultFactory();
- trace(chain) // ???
- // create a function that returns an object
- var myDynamicDefinition:Function = function() {
- this.name = "initialvalue";
- trace('this.name='+this.name); // returns this.name=initialvalue
- }
- var dynamicDefinitionInstance = new myDynamicDefinition(); // create an instance of myDynamicDefinition
- trace(ObjectUtil.toString(dynamicDefinitionInstance));// returns name = "initialvalue"
- // create a new definition and assign it to our dynamic definitions
- var newDefinition = {color:"red", name:"newObjectValue"};
- myDynamicDefinition.prototype = newDefinition;
- // create a new instance with new definition
- var dynamicDefinitionInstance2 = new myDynamicDefinition(); // create an instance of myDynamicDefinition
- trace(ObjectUtil.toString(dynamicDefinitionInstance2)); // returns name = "initialvalue" color = "red"
- // delete name property instance
- delete dynamicDefinitionInstance2.name;
- trace(ObjectUtil.toString(dynamicDefinitionInstance2)); // returns name = "newObjectValue" color = "red"
- // set prototype to null
- myDynamicDefinition.prototype = null;
- // create a new instance
- var dynamicDefinitionInstance3 = new myDynamicDefinition();
- trace(ObjectUtil.toString(dynamicDefinitionInstance2)); // returns name = "newObjectValue" color = "red"
- newStyleDeclaration.defaultFactory = function():void
- {
- leftMargin = 50;
- rightMargin = 50;
- }
- var def : Function = function() {
- this.someDefChanges = "someDefChanges";
- }
- var o1 = {testValueO2 : "testValueO2"};
- def.prototype = o1;
- var o2 = new def();
- def.prototype = null;
- // o1 = {testValueO2: "testValueO2"}
- // o2 = {someDefChanges: "someDefChanges", testValueO2: "testValueO2"}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement