Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. function addDefaultStyleToProtoChain(chain):Object {
  2. // If there's a defaultFactory for this style sheet,
  3. // then add the object it produces to the chain.
  4. if (defaultFactory != null)
  5. {
  6. var originalChain:Object = chain;
  7.  
  8. // from here on...
  9. defaultFactory.prototype = chain;
  10. chain = new defaultFactory();
  11. defaultFactory.prototype = null;
  12. }
  13.  
  14. return chain;
  15. }
  16.  
  17. var o:Object = new defaultFactory();
  18. trace(o) // {fontFamily:Arial, color:blue};
  19. trace(chain) // {color:red, fontWeight:bold}
  20.  
  21. defaultFactory.prototype = chain;
  22. chain = new defaultFactory();
  23. trace(chain) // ???
  24.  
  25. // create a function that returns an object
  26. var myDynamicDefinition:Function = function() {
  27. this.name = "initialvalue";
  28. trace('this.name='+this.name); // returns this.name=initialvalue
  29. }
  30.  
  31. var dynamicDefinitionInstance = new myDynamicDefinition(); // create an instance of myDynamicDefinition
  32. trace(ObjectUtil.toString(dynamicDefinitionInstance));// returns name = "initialvalue"
  33.  
  34. // create a new definition and assign it to our dynamic definitions
  35. var newDefinition = {color:"red", name:"newObjectValue"};
  36. myDynamicDefinition.prototype = newDefinition;
  37.  
  38. // create a new instance with new definition
  39. var dynamicDefinitionInstance2 = new myDynamicDefinition(); // create an instance of myDynamicDefinition
  40. trace(ObjectUtil.toString(dynamicDefinitionInstance2)); // returns name = "initialvalue" color = "red"
  41.  
  42. // delete name property instance
  43. delete dynamicDefinitionInstance2.name;
  44. trace(ObjectUtil.toString(dynamicDefinitionInstance2)); // returns name = "newObjectValue" color = "red"
  45.  
  46. // set prototype to null
  47. myDynamicDefinition.prototype = null;
  48.  
  49. // create a new instance
  50. var dynamicDefinitionInstance3 = new myDynamicDefinition();
  51. trace(ObjectUtil.toString(dynamicDefinitionInstance2)); // returns name = "newObjectValue" color = "red"
  52.  
  53. newStyleDeclaration.defaultFactory = function():void
  54. {
  55. leftMargin = 50;
  56. rightMargin = 50;
  57. }
  58.  
  59. var def : Function = function() {
  60. this.someDefChanges = "someDefChanges";
  61. }
  62.  
  63. var o1 = {testValueO2 : "testValueO2"};
  64. def.prototype = o1;
  65. var o2 = new def();
  66. def.prototype = null;
  67.  
  68. // o1 = {testValueO2: "testValueO2"}
  69. // o2 = {someDefChanges: "someDefChanges", testValueO2: "testValueO2"}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement