$和$ .fn有什么区别? [英] What is the difference between $ and $.fn?
问题描述
我很好奇,不知道$
和$.fn
之间的区别?任何人都可以向我详细解释一下吗?还有什么是$.fn
?
I am too curious to know the difference between $
and $.fn
? Can anyone please explain this to me in details? Also what is $.fn
?
推荐答案
$
是一个函数(特别是指向jQuery
函数的变量别名). $.fn
是该函数的属性,它指向jQuery用于创建实例的内部init
函数的原型,如我们在jQuery代码中所见:
$
is a function (specifically, a variable pointing to the jQuery
function — an alias). $.fn
is a property on that function, which points to the prototype of the internal init
function jQuery uses to create instances, as we can see in the jQuery code:
jQuery.fn.init.prototype = jQuery.fn;
(这是当前未缩小的jQuery文件v1.8.3.的第289行)
(That's line 289 of the current un-minified jQuery file, v1.8.3.)
$.fn
在那里,因此可以轻松地向其中添加属性.当您创建jQuery对象时,由于JavaScript的原型继承,它们具有那些属性.当然,最常用的属性是执行功能的功能(jQuery插件).
$.fn
is there so that it's easy to add properties to it. When you create jQuery objects, they have those properties, because of JavaScript's prototypical inheritance. The most common properties to add to it are, of course, functions that do things (jQuery plug-ins).
这篇关于$和$ .fn有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!