- Michael Barton |
- JavaScript, jQuery |
- February 8th, 2011
This blog is more for myself than any of you readers out there. Every so often I need to have an object of some kind or a function that has its own defaults. Here’s how to do it using jQuery:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // function function myFunc(options) { var defaults = {option1: 'val', option2: 'val2'}; var settings = $.extend({}, defaults, options); // do something } // or, an object var myObj = { init: function(options) { var defaults = {option1: 'val', option2: 'val2'}; var settings = $.extend({}, defaults, options); } }; |

