if i extend the jquery fn(like $.fn.extend) i write my plugin:
(function($){
$.fn.extend({
functionName : function(){
//function returns
return this.each(function(){
$(this).append("<div>text</div>");
});
}
});
})(jQuery);
when i want to extend jQuery namespace i write it like this:
(function($){
$.extend({
functionName : function(){
//function returns
}
});
})(jQuery);
what i don’t know is how to write the ‘return’ in this case
UPDATE
When you are doing multiple operations involving more than one selector, you have to decide what makes the most sense. If one selector is the primary focus, but effects other items as well, write it like a plugin, and return the primary result set like this:
If the selectors are all equal in importance, then simply create a function that does not return anything or returns
true/falsedepending on success.Another way to structure the code:
The extend method is used in other OOP frameworks and as you have shown, can be used with jQuery as well. What you will find, however, is many jQuery developers opt for the shorter more obvious syntax like this: