backbone extend 原始碼分析

2022-02-26 18:58:42 字數 913 閱讀 4865

var extend = function(protoprops, staticprops)  else 

/*定義child是子類的構造器函式*/

_.extend(child, parent, staticprops);

/* 擴充套件 child的靜態屬性和方法,這裡預設所有子類有extend靜態方法,理解for(var i in function) */

var surrogate = function();

/* 在 new的時候重寫constructor屬性 */

surrogate.prototype = parent.prototype;

/* 即使這裡的constructor被汙染了也沒有關係,拿到父類prototype的所有方法 */

child.prototype = new surrogate();

/*因為 prototype之後 child.prototype.constructor指向child ,這裡必須是new一下 ,轉殖child物件 */

if (protoprops) _.extend(child.prototype, protoprops);

/*最後一步 新增子類的方法到 child的prototype上*/

child.__super__ = parent.prototype;

return child;

/*返回子類構造器函式*/

};model.extend = collection.extend = router.extend = view.extend = history.extend = extend;

/*給backbone.model,backbone.collection, backbone.router,backbone.view新增extend靜態方法。 函式是物件,此處引用*/

官方源 映象源彙總

網易 http 阿里雲 http 上海交通大學 http ftp.sjtu.edu.cn html resources.xml 部分移動運營商出口狀況不佳,無法訪問 華中科技大學 http mirror.hust.edu.cn 當前已用容量估計 4.83t 清華大學 http mirrors.tun...

官方源 映象源彙總

網易 阿里雲 上海交通大學 部分移動運營商出口狀況不佳,無法訪問 華中科技大學 當前已用容量估計 4.83t 清華大學 當前已用容量估計 9.8t 北京理工大學 蘭州大學 中國科技大學 當前已用容量估計 21.32t 大連東軟資訊學院 當前已用容量估計 2.5t 東北大學 大連理工大學 哈爾濱工業大...

官方源 映象源彙總

網易 阿里雲 上海交通大學 部分移動運營商出口狀況不佳,無法訪問 華中科技大學 當前已用容量估計 4.83t 清華大學 當前已用容量估計 9.8t 北京理工大學 蘭州大學 中國科技大學 當前已用容量估計 21.32t 大連東軟資訊學院 當前已用容量估計 2.5t 東北大學 大連理工大學 哈爾濱工業大...