Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does jQuery makes the jQuery object both a function and an object property?

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

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

How can you achieve a such thing in Javascript?

like image 460
SBSTP Avatar asked Aug 16 '11 04:08

SBSTP


1 Answers

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

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

and then extend it

$.fadeTo = function() { alert('fadeto'); }
like image 156
wesbos Avatar answered Oct 12 '22 00:10

wesbos