【发布时间】:2012-08-22 00:51:57
【问题描述】:
好的!首先,这个问题来自一个在 jQuery 世界中挖掘得太深(并且可能迷失方向)的人。
在我的研究中,我发现 jquery 的主要模式是这样的(如果需要更正,欢迎您):
(function (window, undefined) {
jQuery = function (arg) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init(arg);
},
jQuery.fn = jQuery.prototype = {
constructor: jQuery,
init: function (selector, context, rootjQuery) {
// get the selected DOM el.
// and returns an array
},
method: function () {
doSomeThing();
return this;
},
method2: function () {
doSomeThing();
return this;,
method3: function () {
doSomeThing();
return this;
};
jQuery.fn.init.prototype = jQuery.fn;
jQuery.extend = jQuery.fn.extend = function () {
//defines the extend method
};
// extends the jQuery function and adds some static methods
jQuery.extend({
method: function () {}
})
})
当$ 启动时,jQuery.prototype.init 启动并返回一个元素数组。但我不明白它是如何添加像.css 或.hide 等的jQuery 方法的。到这个数组。
我得到了静态方法。但是无法通过所有这些方法获得它的返回方式和元素数组。
【问题讨论】:
标签: javascript jquery oop reverse-engineering