顯示廣告
隱藏 ✕
※ 本文為 Knuckles 轉寄自 ptt.cc 更新時間: 2012-10-11 04:28:35
看板 Ajax
作者 etrexetrex (moonet)
標題 [心得] JS的物件導向類別範本
時間 Fri Feb 24 17:41:43 2012


blog本文 : http://etrex.blogspot.com/2012/02/js-oop-class-template.html



為了節省大家的時間

我在看完了物件導向那篇文章之後
物件導向那篇文章 : http://msdn.microsoft.com/zh-tw/magazine/cc163419.aspx

參考 EaselJS 寫了一個 class 的範本
EaselJS : http://easeljs.com/
CreateJS | A suite of Javascript libraries and tools for building rich, interactive experiences with HTML5. A suite of Javascript libraries and tools for building rich, interactive experiences with HTML5. ...
 

彩色code : http://paste.plurk.com/show/913157/

黑白code :


(function(window){
    var MyClass = function(){
        //繼承類別的建構式
        繼承類別.call(this,建構式參數);
        //建構式
        this.initialize();
    }
    //繼承類別
    var p = MyClass.prototype = new 繼承類別();

    //static property 靜態屬性
    MyClass.屬性 = 1;
    MyClass.方法 = function(){};

    //public method 公開方法
    p.方法 = function(){};

    //private method 私有方法
    var 方法 = function(){};

    //建構式
    p.initialize = function(){
        //public variable 公開屬性
        this.屬性 = 1;

        //private variable 私有屬性
        var 屬性 = 1;
    }

    //把類別名稱掛在全域上
    window.MyClass = MyClass;
}(window));


--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 210.202.83.105
st900278:很多library都有模擬javascript物件導向 我是用extjs1F 02/26 16:03
gauss02:不錯2F 03/01 01:06

--
※ 看板: KnucklesNote 文章推薦值: 0 目前人氣: 0 累積人氣: 309 
※ 本文也出現在看板: Test
r)回覆 e)編輯 d)刪除 M)收藏 ^x)轉錄 同主題: =)首篇 [)上篇 ])下篇