We all know it's not good to extend an object directly on a native object. So prototype such a library is widely criticized.
Some libraries, such as Lodash, use a toolkit-style extension to bypass the inheritance of objects.
Because of the appearance of the Es6 class, I tried to extend it in the way that the array derives the child object.
Here is a simple example.
' Use strict 'class ABC extends array{ GetArray () { returnthis; } Let x=new ABC (5). Fill (1); Console.log (X.getarray ());
In V8, this example will output the correct result [1,1,1,1,1].
Thereafter, in order to be compatible with other browsers, I tried to use babel.js transcoding to ES5.
But no matter how this step was unsuccessful.
Finally I went into Babel's official discussion group only to know that this was not supported.
Loganfsmyth gives a notation
class Extendablearray { constructor (... args) { new Array (... args); This . Constructor.prototype); return arr; }}
But obviously, instanceof and Array.isarray and so on will have problems.
Therefore, there is no perfect alternative at this stage.
Many people say that many of the things in es6 are grammatical sugars.
Yes, that's true.
However, as the scripting language, the more refined the script, the faster the scanning speed, the performance potential of the compressor will increase.
Lengthy grammar has never been meaningful, needed, or written in a neat way.
Many of the features of ES6 are useful for these points.
The appearance of the module unifies the current cumbersome loading mode.
A series of asynchronous statements have been proposed to solve the callback hell.
The proposed class simplifies the inheritance process.
The more basic data structures optimize the data processing performance.
Although efficiency is not taken into account, ES6 can do it, and ES5 can do most of it.
But ES5 can't do better.
program, must be graceful.
Failed attempts, using an inherited extended array, and the necessity of ES6