In this post, the author is using:
$.fn.wPaint = function(settings) {
settings = $.extend({}, defaultSettings, settings || {});
Q: Wouldn’t that overwrite the settings variable the calling scope? I would think you’d want to create a new variable, which would mean that you’d have a total of 3 variables:
- The Default settings in the closure scope
- The settings in the arguments
- The settings in the local scope
The settings argument is a reference to a variable in the calling scope. Inside your function you are assigning a new object to the settings variable, this breaks the reference and points the local variable to a new value in the local scope. If you modified settings, without assigning to it, it would affect the settings in the calling scope. The settings in the arguments is the settings in the local scope.