jQuery如何使jQuery对象既是一个函数又是一个对象属性?

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'); }