Hey, I was wondering if setting an object equal to $.extend(), but setting the target to the same object is redundant?
setOptions(options = $.extend({
classPrefix: 'imgareaselect',
movable: true,
resizable: true,
parent: 'body',
onInit: function () {},
onSelectStart: function () {},
onSelectChange: function () {},
onSelectEnd: function () {}
}, options));
They way you’ve coded it, it’s not redundant. That’s because the first object passed in is the one that’s modified, so all of the properties in
optionsare being copied to the anonymous object you pass in as the first parameter. So you would then need to assign the return value of$.extendto something in order by be able to actually use it. If you’d done it the other way around:Then the assignment is redundant. Note also that the order you pass objects in is important. By doing it the way you’ve done it, the anonymous object is basically the “defaults” and anything in
optionswill override them.Finally, because you’re passing the result to a call to
setOptions(which I assume saves the value somewhere) you also don’t need an explicit assignment tooptions. But that depends entirely on whatsetOptionsdoes and what you needoptionsfor later…