function Spinner (target, options = {}) { = { "Please Wait", 5, ". is-spinning" }; = Object.assign ( {}, defaults, options ); if (Settings.spinningspeed!== defaults.spinningspeed) { = _addspeedclass (target); } _renderspinner (target, settings);}
- Best Pratices to write defaults as a objects, much clean and reuseable.
- Write a empty object {} to the object.assign is recommened, it avoid defaults been mutated.
- If block, you see we might still use default value, so it's important to keep the origin defautls value.
Example2:
function Spinner (target, options = {}) { = { "Please Wait", 5, ". is-spinning" }; = object.assign ({}, defaults, options); Console.log (' Message: ${settings.message} '); Console.log (' Spinningspeed: ${settings.spinningspeed} '); Console.log (' CssClass: ${settings.cssclass} ');} Spinner (Targetelement, { ". is-fast-spinning", 8 });
[ES6] Object.assign (with defaults value object)