我有兩個關於下面的代碼片段的問題。 (1)JQuery源代碼問題
(1)。 「返回新的jQuery.fn.init(選擇器,上下文,rootjQuery)」的目的是什麼?爲什麼它會在JQuery函數中返回另一個實例?
(2)。爲什麼prototype.constructor被重新定義爲JQuery?
// Define a local copy of jQuery
var jQuery = function(selector, context) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init(selector, context, rootjQuery);
},
... ...
jQuery.fn = jQuery.prototype = {
constructor: jQuery,
init: function(selector, context, rootjQuery) {
var match, elem, ret, doc;
謝謝!
羅布嗨,什麼是「rootjQuery」參數?謝謝。 – Ricky
'rootQuery'是引用文檔的JQuery包裝的根的內部參數。 –