Prototype chain
Examples are as follows:
var arr = [1, 2, 3];
Its prototype chain is:arr ----> Array.prototype ----> Object.prototype ----> null
In the same vein, we create a function:
function foo () { return 0;}
Its prototype chain is:foo ----> Function.prototype ----> Object.prototype ----> null
Because Function.prototype
apply()
such methods are defined, all functions can invoke apply()
methods.
It is easy to think that if the prototype chain is long, then accessing an object's properties will become slower because it takes more time to find it, so be careful not to make the prototype chain too long.
constructor function
constructor if not written new
, this is a normal function that returns undefined
. However, if new
it is written, it becomes a constructor that binds to the this
newly created object and returns by defaultthis。
That is, there is no need to write at the end return this;
.
new Student()
the created object also obtains a property from the prototype constructor
, which points to the function Student
itself.
Arrow functions
x = x * x
The above arrow functions are equivalent to:
function (x) { return x * x;}
Se6 Array de-weight
function Dedupe (array) { return array.from (new Set (array)); } Console.log (Dedupe ([//[+]
Array.form creating an array from a string
Prototype chain, constructor, arrow function, se6 array de-weight