jquery function shorthand
Is th开发者_如何学编程ere any shorthand for this?
(function($) {
$.fn.DoStuff= function() {
// do stuff
};
})(jQuery);
This will be placed in separate file.
And than to be called like that from another file from inside $(document).ready( function(){});:
$('element').DoStuff();
?
you could write a jQuery plugin, e.g.
$.fn.DoStuff = function () {
this === $('element');
...
};
here's working example: http://jsfiddle.net/xW3ZD/
not really, you can do
(function($) {
$.fn.extend({
DoStuff: function(options) {
//stuff
};
})(jQuery);
which can still be called $(selector).DoStuff(options);
but it's not a lot shorter and it extends the jquery object rather than being it's own function.
精彩评论