Posted By

msstar on 11/05/12


Tagged

plugin jquery extend


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Some0ne
BrockSamsom


The difference between jQuery.extend() and jQuery.fn.extend()


 / Published in: jQuery
 

The difference between jQuery.extend() and jQuery.fn.extend()

  1. $.fn.extend({
  2. myMethod: function(){...}
  3. });
  4. //jQuery("div").myMethod();
  5.  
  6. $.extend({
  7. myMethod2: function(){...}
  8. });
  9. //jQuery.myMethod2();
  10.  
  11. defaults = { size: 3 };
  12. options = { height: 6 };
  13. var opts = $.extend(defaults, options)
  14. // 'defaults' receives the methods and variables defined in 'options'
  15. // opts == defaults == { size: 3, height: 6 }
  16. // options == { height: 6 };
  17.  
  18. <pre>var opts = $.extend( {}, defaults, options)
  19. // 'opts' gets all methods and variables defined in 'defaults' and 'options',
  20. // neither of them get modified.
  21. // opts == { size: 3, height: 6 }
  22. // defaults == { size: 3 };
  23. // options == { height: 6 };

Report this snippet  

You need to login to post a comment.