Recently, when implementing a class method, the younger brother must pass parameters to ensure that the new keyword is not used to generate strength. So it took a lot of effort,CodeStill not beautiful enough. Finally, the answer is es6's spread.
See https://github.com/Neverland/Class/blob/master/script/class.js for details
Es6 official explanation of SPRED is:
- Replace an array or array-like actual parameter value with its elements as positional parameters
- Let
New
Compose withThis
-Free FormApply
- Remove (some day, and in similar future methods) automagic (and half-the-time wrong) array flattening, e.g. In
Array. Prototype. Concat
As follows
1. Replace the actual parameter values such as arrays or arrays with multiple positional parameters.
2. You do not need to consider using apply when using new.
3. Remove automated array flattening
Syntax:
... Very simple.
Case study:
1. If both new and apply are used, the syntax will be incorrect. // new elements. Apply (document. getelementsbytagname ('div '));
NewElements(...doc ument. getelementsbytagname ('div '));
2. Structure assignment, which can be split into segments
VaR [A,... B] = [1, 2, 3, 4];
A // 1;
B // [2, 3, 4]
3. Directly disassemble class arrays or array parameters when calling a function
VaR A = [1, 2, 4];
If array a is split into four values when a function is called
Add. Apply (this, );
Now
Add (... );