【发布时间】:2016-05-11 13:52:17
【问题描述】:
查看旧 jQuery 版本的休闲结构:
(function( window, undefined ) {
var jQuery = (function() {
var jQuery = function( selector, context ) {
return new jQuery.fn.init( selector, context );
};
jQuery.fn = jQuery.prototype = {
init: function( selector, context ) {
// ...
return this;
}
// jQuery API methods
}
// Give the init function the jQuery prototype for later instantiation
jQuery.fn.init.prototype = jQuery.fn;
return (window.jQuery = window.$ = jQuery);
})();
})(window);
这很容易理解:
jQuery.fn = jQuery.prototype = {
init: function( selector, context ) {
return this;
}
}
jQuery.fn.init.prototype = jQuery.fn;
是在以正常用法调用 jQuery 时触发的一个部分,例如
$('p')
或
jQuery('p')
目前还不清楚如何使用 $.ajax() 或 $.isArray() 形式调用 API 方法,以及您将在哪里放置(比方说)列出的代码中的自定义方法并使用 $.myCustomMethod( )。
任何帮助将不胜感激。
【问题讨论】:
-
其实很简单……想想这个提示:每个函数在 JavaScript 中也是一个普通对象。
-
我不确定是什么问题:
$有属性,这些属性可以是方法。
标签: javascript jquery