如何创建jQuery函数? [英] How to create jQuery functions?

查看:219
本文介绍了如何创建jQuery函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了几种创建jQuery(-namespaced)函数的方法,但是我不能确切地说出它们之间的实际区别.

I have seen a few different approaches to create jQuery(-namespaced) functions, but I cannot quite tell the actual difference between them.

jQuery.fn.myFunction = function() { ... };

jQuery.myFunction = function() { ... };

jQuery.fn.extend({ myFunction: function() { ... } });

推荐答案

jQuery.fn.myFunction是您用来创建将在每个jQuery结果集上都可用的函数的

jQuery.fn.myFunction is what you use to create functions that will be available on every jQuery result set:

$('div').myFunction();

jQuery.myFunction是您用来创建仅在jQuery对象上可用的帮助器功能的功能,例如$.inArray

jQuery.myFunction is what you use to create helper functions that are just available on the jQuery object, such as $.inArray

您的最新版本使用新功能扩展了$.fn对象,因此与您的第一个示例等效.

Your last version extends the $.fn object with a new function, and is as such the functional equivalent of your first example.

这篇关于如何创建jQuery函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆