/ Published in: jQuery

The difference between jQuery.extend() and jQuery.fn.extend()
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$.fn.extend({ myMethod: function(){...} }); //jQuery("div").myMethod(); $.extend({ myMethod2: function(){...} }); //jQuery.myMethod2(); defaults = { size: 3 }; options = { height: 6 }; var opts = $.extend(defaults, options) // 'defaults' receives the methods and variables defined in 'options' // opts == defaults == { size: 3, height: 6 } // options == { height: 6 }; <pre>var opts = $.extend( {}, defaults, options) // 'opts' gets all methods and variables defined in 'defaults' and 'options', // neither of them get modified. // opts == { size: 3, height: 6 } // defaults == { size: 3 }; // options == { height: 6 };
Comments
