$(obj) allows you to create an empty jQuery object, but this is different from $()
For example: I have a solution with a namespace that needs to have custom events that take action based on a centralized object. I wrote my own EventHandler class, which basically wraps a private $({})
This allows me to have an object that can act as my event holder and trigger. I expand bind (), unbind () and trigger () in the EventHandler class.
$() , on the other hand, does not allow to bind and run, since there is no base object. I am not completely sure of my ideas with this, since it would be more reasonable for the jQuery object "default" or "empty" to be $({})
In short: there are things that $({}) does, that $() does not. But $([]) and $() seem to work the same way with the minimum number of tests I did. Maybe $(new Array()) acts differently, but I don't want to explore it.
EDIT with an example:
var testA = $(); testA.bind('customEvent', function () { alert('empty custom'); }); testA.trigger('customEvent'); // will not get an alert var testB = $({}); testB.bind('customEvent', function() { alert('object custom'); }); testB.trigger('customEvent'); // will get an alert var testC = $([]); testC.bind('customEvent', function () { alert('array custom'); }); testC.trigger('customEvent'); // acts like testA
Anthony sottile
source share