Following the good jQuery Plugins / Authoring instructions , I have a little question
(function($){ // Default Settings var settings = { var1: 50 , var2: 100 }; var methods = { init : function (options) { console.log(settings); settings = $.extend(options, settings); // Overwrite settings console.log(settings); return this; } , other_func: function () { return this; } }; $.fn.my_plugin = function (method) { if (methods[method]) { return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); } else if (typeof method === 'object' || ! method) { return methods.init.apply(this, arguments); } else { $.error('Method ' + method + ' does not exist on jQuery.my_plugin'); } }; })(jQuery);
If i do
>>> $('my_element').my_plugin({var3: 60}) Before Object { var2=100, var1=50} After Object { var3=60, var2=100, var1=50} [ my_element ] >>> $('my_element').my_plugin({var1: 60}) Before Object { var1=50, var2=100} After Object { var1=50, var2=100} [ my_element ]
Why is my var1
not overridden?
source share