JS設計模式之簡單工廠模式

$(function () {
     var userNameAlter=createPopup("alert","驗證");
});

function createPopup(type,text){
    var o=new Object();
    o.content=text;
    o.show=function () {
        alert("顯示");
    }
    if(type=="alert"){
        o.show();
    }
    if(type=="promot"){

    }
    if(type=="confirm"){

    }

    return o;
}

通過寄生式繼承得到純淨的對象,雖然這個模式有很多的不足

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章