2022年8月3日 星期三

建構子 function() { this.modelType=0; this.getModelType=function{return this.modeltype;}

/*
 * 建構子會如此做動:
 *
 * function MyConstructor(){
 *   // 實際的函式主體碼在這裡
 *   // 在|this| 上創建屬性
 *   // 希望通過分配給他們,如:
 *   this.fum = "nom";
 *   // et cetera...
 *
 *   // 如果函式有返回狀態它將返回一個物件
 *   // 那個物件將是新表達式的結果。
 *   // 換句話來說,表達式的結果是現在綁定 |this| 的物件
 *   // (例如,最常見的常見情況).
 * }
function C(){

this.a = 37; } var o = new C();

console.log(o.a); // logs 37



//static var
var buttonModel = function () {
    this.modelType = 0; //預設檢視模式
    this.getModelType = function () {
        return this.modelType;
    }
}

沒有留言:

張貼留言