jquery教程

推荐列表 站点导航

当前位置:首页 > jquery > jquery教程 >

jQuery.fn和jQuery.prototype区别介绍

来源:网络整理  作者:  发布时间:2020-12-21 03:10
jQuery.fn和jQuery.prototype想必大家对它并不陌生吧,那么你们知道它们之间的区别吗?在本文有个不错的示例大家可以参...


这里有个问题。
jQuery.fn = jQuery.prototype = {
};

复制代码 代码如下:

})(window);
// something to do


那么在这之前jQuery.fn.init.prototype.是什么?

那么就是 将jQuery 的原型对象赋值给了 jQuery.fn。

复制代码 代码如下:

jQuery.fn.init.prototype = jQuery.fn;

return new jQuery.fn.init( selector, context, rootjQuery );
就是从这里来的,一个javascript对象。


constructor: jQuery,
jQuery.extends()是直接扩展jQuery.而jQuery.fn.extends(),很明显是扩展的原型。
}
再看下面:


// 合并内容到第一个参数中,后续大部分功能都通过该函数扩展
来看下jQuery的源码是怎么样定义的:

复制代码 代码如下:


})();
jQuery.extends()
jQuery.fn = jQuery.prototype = {
// something to do
// 在jQuery上扩展静态方法



复制代码 代码如下:

}


var jQuery = function( selector, context ) {

jQuery.fn.init.prototype的原型也就是jQuery的原型对象就是 jQuery.fn ( 注意jQuery = function(return new jQuery.fn.init()))。
jQuery 其实jQuery.fn.init()返回一个对象。那么jquery.fn.init()返回的又是什么呢?

return jQuery;
}

var jQuery = (function() {


// 到这里,jQuery对象构造完成,后边的代码都是对jQuery或jQuery对象的扩展
jQuery.fn.extends()
(function( window, undefined ) {
jQuery.fn.init.prototype = jQuery.fn;


}
将jQuery.fn 赋值给jQuery.fn.init.prototype.这样的话,

复制代码 代码如下:

// 通过jQuery.fn.extend扩展的函数,大部分都会调用通过jQuery.extend扩展的同名函数

那么为了可以去调用init外面的方法。就做了一个处理。


jQuery.extend({

你可能会想到这样一个东东:
// something to do
constructor: jQuery,
那么这样的话。
这就是为什么jQuery.fn.extends()中的大部分方法来自己于jQuery.extends()。

复制代码 代码如下:

这里我们可以看到:
// jQuery对象原型
是不是没有?这个时候它的原型是{};



发现这里有个东西很难理解。

看到这里我有一个想法。就是 将jQuery.fn 给了 jQuery.fn.init.prototype.

init: function( selector, context, rootjQuery ) {
return new jQuery.fn.init( selector, context, rootjQuery );


复制代码 代码如下:

我想你应该明白它们的区别了吧。
window.jQuery = window.$ = jQuery;


这里的 jQuery , jQuery.fn , jQuery,fn,init ,jQuery,prototype 都代表什么。



近期在读jquery的源码。
};


jQuery.prototype = jQuery.fn = jQuery.fn.init.prototype
// 构建jQuery对象
// Give the init function the jQuery prototype for later instantiation



这里又将 jQuery.fn 赋值给了 jQuery.fn.init.prototype.
jQuery.fn = jQuery.prototype
});


赋值了以后。在调用的时候,当init中没有方法的时候,就会去原型函数中调用。

jQuery.extend = jQuery.fn.extend = function() {};
var jQuery = function( selector, context ) {
init: function( selector, context, rootjQuery ) {
那么就有这样的一个关系:

相关热词: jquery

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/jq/jc/6459.shtml

相关文章
最新文章
PHP识别相片是否是颠倒的 PHP识别相片是否是颠倒的

时间:2020-12-28

python编程有哪些ide python编程有哪些ide

时间:2020-12-28

python开发工程师是做什么 python开发工程师是做什么

时间:2020-12-28

php构造函数的作用 php构造函数的作用

时间:2020-12-28

php怎么跟数据库连接 php怎么跟数据库连接

时间:2020-12-28

php实现顺序线性表 php实现顺序线性表

时间:2020-12-28

Python多重继承中的菱形继 Python多重继承中的菱形继

时间:2020-12-28

php中break的作用 php中break的作用

时间:2020-12-28

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

jQuery.fn和jQuery.prototype区别介绍

2020-12-21 编辑:



这里有个问题。
jQuery.fn = jQuery.prototype = {
};

复制代码 代码如下:

})(window);
// something to do


那么在这之前jQuery.fn.init.prototype.是什么?

那么就是 将jQuery 的原型对象赋值给了 jQuery.fn。

复制代码 代码如下:

jQuery.fn.init.prototype = jQuery.fn;

return new jQuery.fn.init( selector, context, rootjQuery );
就是从这里来的,一个javascript对象。


constructor: jQuery,
jQuery.extends()是直接扩展jQuery.而jQuery.fn.extends(),很明显是扩展的原型。
}
再看下面:


// 合并内容到第一个参数中,后续大部分功能都通过该函数扩展
来看下jQuery的源码是怎么样定义的:

复制代码 代码如下:


})();
jQuery.extends()
jQuery.fn = jQuery.prototype = {
// something to do
// 在jQuery上扩展静态方法



复制代码 代码如下:

}


var jQuery = function( selector, context ) {

jQuery.fn.init.prototype的原型也就是jQuery的原型对象就是 jQuery.fn ( 注意jQuery = function(return new jQuery.fn.init()))。
jQuery 其实jQuery.fn.init()返回一个对象。那么jquery.fn.init()返回的又是什么呢?

return jQuery;
}

var jQuery = (function() {


// 到这里,jQuery对象构造完成,后边的代码都是对jQuery或jQuery对象的扩展
jQuery.fn.extends()
(function( window, undefined ) {
jQuery.fn.init.prototype = jQuery.fn;


}
将jQuery.fn 赋值给jQuery.fn.init.prototype.这样的话,

复制代码 代码如下:

// 通过jQuery.fn.extend扩展的函数,大部分都会调用通过jQuery.extend扩展的同名函数

那么为了可以去调用init外面的方法。就做了一个处理。


jQuery.extend({

你可能会想到这样一个东东:
// something to do
constructor: jQuery,
那么这样的话。
这就是为什么jQuery.fn.extends()中的大部分方法来自己于jQuery.extends()。

复制代码 代码如下:

这里我们可以看到:
// jQuery对象原型
是不是没有?这个时候它的原型是{};



发现这里有个东西很难理解。

看到这里我有一个想法。就是 将jQuery.fn 给了 jQuery.fn.init.prototype.

init: function( selector, context, rootjQuery ) {
return new jQuery.fn.init( selector, context, rootjQuery );


复制代码 代码如下:

我想你应该明白它们的区别了吧。
window.jQuery = window.$ = jQuery;


这里的 jQuery , jQuery.fn , jQuery,fn,init ,jQuery,prototype 都代表什么。



近期在读jquery的源码。
};


jQuery.prototype = jQuery.fn = jQuery.fn.init.prototype
// 构建jQuery对象
// Give the init function the jQuery prototype for later instantiation



这里又将 jQuery.fn 赋值给了 jQuery.fn.init.prototype.
jQuery.fn = jQuery.prototype
});


赋值了以后。在调用的时候,当init中没有方法的时候,就会去原型函数中调用。

jQuery.extend = jQuery.fn.extend = function() {};
var jQuery = function( selector, context ) {
init: function( selector, context, rootjQuery ) {
那么就有这样的一个关系:

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/jq/jc/6459.shtml

相关文章

风云图片

推荐阅读

返回jquery教程频道首页