Javascript 创建类库jQuery样式
我目前正在研究jQuery是如何工作的,但我没有什么问题Javascript 创建类库jQuery样式,javascript,jquery,Javascript,Jquery,我目前正在研究jQuery是如何工作的,但我没有什么问题 jQuery.fn=jQuery.prototype={}为什么prototype=object,prototype不是通常在jQuery.prototype.foo=function… var init=jQuery.fn.init(jQuery.prototype.init)当我删除var init时,我得到了一个错误,如下所示:var jQuery.fn.init=… 1)jQuery.fn=jQuery.prototype={};
jQuery.fn=jQuery.prototype={}代码>为什么prototype=object
,prototype不是通常在jQuery.prototype.foo=function…
var init=jQuery.fn.init(jQuery.prototype.init)
当我删除var init
时,我得到了一个错误,如下所示:var jQuery.fn.init=…
var jQuery = function( selector ) {
return new jQuery.fn.init( selector );
};
jQuery.fn = jQuery.prototype = {...};
var init = jQuery.fn.init = function( selector ){
this.selector = selector;
this.element = document.querySelector(this.selector);
};
console.log(
jQuery('div').selector
);
实际上,您正在prototype对象中创建一个名为“get”的成员函数。您也可以这样做:
**jQuery.prototype.get = function(){
//Code
}**
2)删除init时,语句将变为var jQuery.fn.init=…
实际上,这不是有效的语句,因为jQuery对象已经可用。这是一个语法错误。不能创建这样的任何对象的成员。
为此,你只需要做
**jQuery.prototype = {
"get" : function(){
}
}**
1)jQuery.fn=jQuery.prototype={};为什么原型=对象
事实上,只有当你做了这样的事情,原型才是一个对象
var jQuery = function( selector ) {
return new jQuery.fn.init( selector );
};
jQuery.fn = jQuery.prototype = {...};
var init = jQuery.fn.init = function( selector ){
this.selector = selector;
this.element = document.querySelector(this.selector);
};
console.log(
jQuery('div').selector
);
实际上,您正在prototype对象中创建一个名为“get”的成员函数。您也可以这样做:
**jQuery.prototype.get = function(){
//Code
}**
2)删除init时,语句将变为var jQuery.fn.init=…
实际上,这不是有效的语句,因为jQuery对象已经可用。这是一个语法错误。不能创建这样的任何对象的成员。
为此,你只需要做
**jQuery.prototype = {
"get" : function(){
}
}**
var
-部分时,您基本上删除了完整的
定义。变量名不能包含点,因为点乘
定义需要一个对象。因此,var a.b.c=1
不会
是有效的。您需要有一个对象a={b:{}
,然后执行以下操作
a.b.c=1
var
-部分时,您基本上删除了完整的
定义。变量名不能包含点,因为点乘
定义需要一个对象。因此,var a.b.c=1
不会
是有效的。您需要有一个对象a={b:{}
,然后执行以下操作
a.b.c=1
jQuery.fn.init=jQuery.prototype.init吗?这与jQuery.prototype={}对象有关吗?jQuery.fn.init=jQuery.prototype.init吗?这与jQuery.prototype={}对象有关吗?