In jQuery using $ .extend (), is this redundant?

Hey, I was interested in setting an object equal to $ .extend (), but setting a target on 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));
+3
source share
1 answer

They, as you encoded it, are not redundant. This is because the first object that was passed is the one that was changed, so all properties in are optionscopied to the anonymous object that you pass as the first parameter. Thus, then you will need to assign the return value $.extendto something so that it can actually use it. If you did it the other way around:

$.extend(options, { ... });

. , , , . , , " ", - options .

, setOptions (, , -), options. , setOptions options ...

+2

Source: https://habr.com/ru/post/1752011/


All Articles