行!首先,这个问题来自一个在 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启动并返回一个元素数组。但我无法理解它是如何添加 jQuery 方法的,例如.css或.hide等。到这个数组。
我得到了静态方法。但是无法获得所有这些方法的返回方式和元素数组。