tags: JS senior learning js
Common built-in class in JS
Custom class "class-> constructor"
ES5: Create a function, perform a function based on "New", this function is called the constructor "class", the result is an instance of the class
ES6: Create a custom class based on "Class"
JS code runtime:
Ordinary function execution:
NEW execution function: (execute the function as constructor)
example:
function Fn(x, y) {
let sum = 10;
this.total = x + y;
this.say = function () {
console.log(`I calculate and is:${this.total}`);
};
}
// let res = fn (10, 20); // Normal function execution => FN function RES function return value
// console.log(res); //undefined
// console.log (window.total, window.say, window.sum); // 30 functions undefined
let f1 = new Fn(10, 20); // Constructor execution => FN constructor (class) F1 class instance
console.log(f1); // Example Object Total & Say

What is the difference between arrow functions and normal functions? Ordinary functions this: This is always representing its direct caller. By default, the direct caller is not found, this refers to ...
The difference between $ and $! The $!{obj} ! symbol indicates that the value is displayed if a value can be obtained. If the value is not obtained or the value is null, the empty string is output &qu...
Difference of arrow function and normal functions 1. Arrow function syntax is more simple than normal functions (each function in ES6 can use shape to participate in default values and remaining ope...
There are two concepts of constructor and function in JavaScript. This may cause some confusion for beginners, it is difficult that there are two functions. However, the composition of these two funct...
Async ES7 keyword, which means asynchronous, can be used alone is used in front of the function, declare that this is an asynchronous function, and then execute it after the synchronization code is ex...
"If your light source is in the heart, you will never lose" Rimmy The last time I have mentioned this problem in the "Overload" of Function Template, but I didn't care. Now let's t...
Constructor (forNew instance object) And normal function differences: The constructor is the same, but the general constructor is generally constructed.First letter is uppercase; Constructor call mode...
The constructor is also a normal function, the creation method is the same as the normal function, but the constructor is used to the first letters. The difference between constructor and ordinary fun...
The difference between constructor execution and ordinary functions Ordinary function execution Form a new private context Initialization Scheme Chain <own context, superior context> Initialize ...
Let's take a look at the function and constructor's small example Definition of function Definition of constructor The two have the same output, all of which are 3 Function of function contains functi...