In the following demo: what is happening in this line of code?
settings = $.extend({}, defaultSettings, settings || {});
What is the difference between the above and this one:
if(settings){
settings = $.extend(defaultSettings, settings);
}
==================================
(function($){
var defaultSettings = {
mode : 'Pencil',
lineWidthMin : '0',
lineWidthMax : '10',
lineWidth : '2'
};
$.fn.wPaint = function(settings)
{
settings = $.extend({}, defaultSettings, settings || {});
return this.each(function()
{
var elem = $(this);
//run some code here
});
}
})(jQuery);
{}.if(settings){- if you don't guaranteesettingsis an object and has been extended withdefaultSettings, you can't use it properly after that.