【发布时间】:2010-12-17 19:48:36
【问题描述】:
小问题是为什么 jQuery 这样做
jQuery.fn = jQuery.prototype = {
init: function() {...},
f1: function() {...},
...
};
jQuery.fn.init.prototype = jQuery.fn;
为什么不简单地将f1() 等添加到init.prototype 中呢?仅仅是审美还是有一些深刻的想法?
【问题讨论】:
-
我不确定您将 f1() 添加到 init.prototype 中是什么意思?它不是在“添加”任何东西,而是在分配原型。
-
当然。我的意思是“分配”当然。对不起我的英语不好。问题是为什么不简单地将所有函数分配给 init.prototype?为什么他们分配给 jQuery.prototype 而不是 jQuery.prototype 分配给 jQuery.prototype.init.prototype
-
jQuery的设计模式相关问题:stackoverflow.com/q/12143590/1048572
标签: javascript jquery