Function package, function package default value

When we encapsulate the function, in order to bring a better user experience to the user, to avoid errors when the user does not input a certain parameter. When encapsulating the function, a default object is encapsulated as the default value.

If we declare an object as a default value in a function, var defaults={key1: value1, key2: value2}. Then call the object.assgin method of the JS object to automatically determine and update the default value.
Object.assgin(defaults, arguments)

Introduce Object.assgin

Shallow copy, target object, source object, there can be multiple source objects, and the last one will be the latest copy.

The return value, if no new variable is assigned, the target object is returned, and the method will affect the source object

Guess you like

Origin blog.csdn.net/Cml_l/article/details/115062185