大佬教程收集整理的这篇文章主要介绍了价值,原型和特性的差异,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我也不喜欢这种模式。他们有一个init
函数,它是所有jquery实例的构造jquery
函数- 函数本身只是对象创建过程的包装器,包括new
:
function jquery(…) { return new init(…); }
然后,他们将那些实例的方法添加到init.prototype
对象中。该对象在处作为接口公开jquery.fn
。此外,他们将prototype
jquery函数的属性设置为该对象-
对于不使用该fn
属性的用户。现在你有
jquery.prototype = jquery.fn = […]init.prototype
但是他们也做两件事:
constructor
原型对象的属性,将其设置为jquery
函数init
功能jquery.fn
-自己的原型。这可能允许扩展$ .fn.init函数,但非常令人困惑我认为他们需要/想要做所有这些事情以防万一,但是他们的代码很烂-从该对象文字开始,然后分配init原型。
好!首先,这个问题来自于一个在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
等。到这个数组。
我得到了静态方法。但是用所有这些方法都无法获得返回值和元素数组的方式。
以上是大佬教程为你收集整理的价值,原型和特性的差异全部内容,希望文章能够帮你解决价值,原型和特性的差异所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。