jQuery 如何使 jQuery 对象既是函数又是对象属性? [英] How does jQuery makes the jQuery object both a function and an object property?

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

问题描述

我一直想知道 jQuery 如何既是函数又是对象属性.

I've been wondering for a long time how jQuery can be both a function and an object property.

您可以像使用函数 jQuery(...) 一样使用它,也可以像使用属性 jQuery.ajax(...) 一样使用它

You can use it like a function, jQuery(...) and you can use it like a property jQuery.ajax(...)

如何用 Javascript 实现这样的功能?

How can you achieve a such thing in Javascript?

推荐答案

函数是 JavaScript 中的对象.这样你就可以拥有你的主要功能

functions are objects in javascript. So you can have your main function

var $ = function() {  alert('wat'); }

然后扩展它

$.fadeTo = function() { alert('fadeto'); }

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

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