Luar's Flash Playground:OOP小貼士
OOP小貼士 (23-08-2003)

兩個在網上看到OOP小貼士:



一、當Object中被監視的Property有改變時,就會激活:

newObject = function () {
    this.i = false;
    this.txt = "hello!";
    this.watch("i", this.on_Change, this.i);
};
newObject.prototype.on_Change = function() {
    this.onChange(arguments[2]);
};
myobj = new newObject();
myobj.onChange = function(value) {
    trace(value);
};
myobj.i = true;
myobj.i = 0;

來自藍色理想經典論壇金山羊的一帖



二、自動繼承屬性:

rootProperties = {
    x:2,
    y:34,
    width:23,
    height:43,
    faceColor:0x343434,
    backColor:0x333333
};
properties = {
    faceColor:0x222222,
    backColor:0x444444,
    __proto__:rootProperties
};
windowProperties = {
    x:34,
    y:45,
    __proto__:properties
};
buttonProperies = {
    x:0,
    y:0,
    height:20,
    backColor:0x888888,
    __proto__:properties
};

buttonProperties.faceColor;
// returns 0x222222 via the "properties" object

windowProperties.height;
// returns 43 via the "rootproperties" object

來自PowerSDK:Ted

本文章由發表。
同組文章