Monday, August 11, 2014

3 interesting details of jQuery functionality

1) $.makeArray - for handling Array-like objects in JS like nodeList and arguments
usually is't workaround by this
[].forEach.call(list, function() {...});

but one can also use:
$.makeArray(list).forEach(function() {...});
2) function attr can do more - removing attribute as well
it meas that
attr('xxx') -> removeAttr('xxx')

or you can have such a nice construction
$(selector).attr(anAttr, condition ? value : null);

3) jQuery.type() instead of typeof

No comments:

Post a Comment