Right and wrong
JS is a computer programming language, a dynamic language, also known as scripting language, and an analytical programming language. Why scripts? Because it cannot execute itself, it means there is no main function or the entrance to the main program, and it must be parsed and executed by its host environment, that is, the parsing environment. What is analytical type? Because JS does not generate a file in a systematic process such as programming, linking, assembly, etc., and then executes it, it loads and executes it in a string form...
True and false in
empty, null, undefined, false,0,"",'', NaN is all false, and the others are true
3. What is the difference between functions, classes, objects, and constructors?
Answer: In js, functions, classes, objects, and constructors can be said to be no difference. We can say that functions are objects, objects are classes, and classes are constructors. But generally, we call objects an instance of that class, which is to reduce confusion.
function Person(){
}
var person = new Person();
//Person we can call it functions, classes, objects, and constructors (without parameters)
//Person is called a reference to an object
4. Understand this keyword, you understand one-fifth of JS.
This always points to the object that calls the method (function). (must be memorized)
First of all, we need to know what this is?
This is an object in js. It is an object, not a function, this is an object, you can see it as a reference to an object, whom? The object that refers to the calling method.
Where does this object exist? It exists in JS code, generally in functions. If you put this into the <script> tag, you can try window==this, what to print? Why?
Analyze this keywords
function ready(){
alert(this==window);
}
ready();
What to hit at this time? true, why?
function Person(){
='Zhang San';
alert(this==window);
}
new Person();
What to print at this time? false, why?
lengthen the code. Add a var perso=
var person = new Person();
People all over the world know that person refers to the object generated by new Person. new Person creates a JS instance object, and we can bind properties and methods.
Look at the following code
fn=function(){
}
=function(){
alert(this== fn);
}
What to print when () is called? true , why?
Very strange, this is now equal to a function... Why?
Static methods and attributes will help you.
What is static? As the name suggests: it means it is not moving. What is the method of not moving in JS? It means that there is no need to create an instance, you can directly call the method through the class name, without moving anywhere. The method is called. No additional code is required. This is just one-sided statement. The so-called static: is the characteristics of the class that belong to the class itself.
Since classes in Js are objects, why can't they directly bind properties and methods? sure.
fn=function(){
}
='Zhang San';
=function(){
return ;
}
This is OK, but why do you still need the new process? Isn’t it okay to bind it like this? think
The impact of constructor in JS framework
prototype is a prototype and is an object. ,.
The constructor is a constructor, a function
Until now, you have to distinguish clearly when the object is an object and when the object is a function. It is also difficult for JS parser to parse and run such flexible code.
prototype can be said to be a static property of a class, which points to an instance of this object. In other words, prototype is an object. What is the difference between the object pointed to by prototype and the object we have new? An equivalent bridge relationship was established, but not the same. When we bind attributes to the function prototype, the attributes and values are bound to the prototype object, and are not really bound to that object. When you need to access this property on that object, the JS parser will first look for this property from the object itself, and then look for it on the prototype object.
function Person(){
}
var person = new Person();
="Zhang San";
="Li Si";
alert();
delete ;
alert();
The constructor points to an object's constructor. (What is a constructor? Review it yourself.), from this we can see that it is an object-level attribute. That is to use the constructor property, an object must be needed.
So does prototype have constructor attributes for an object? Of course there is, since constructor refers to a constructor, is there a prototype attribute? Of course there is, and so on, the following two codes are correct.
……
……
Actually, I don’t know how long it can be? If you are interested, you can try it. By the way, I'll tell you to use recursive algorithms.
Among many JS code, when we know an object, we ask for its constructor, or we know a constructor, we ask for its object. It should be started.
7.== and==Perform the judgment to the end.
== and ===The appearance of the god is not in appearance. Don’t think about it, you can tell at a glance whether the judgment is equal.
Is there any difference?
==Judge whether the variables are equal.
===Judge the values of variables are equal.
And so on:====What is it used for? ? Used to report an error. You know. I just want to tell you here, only == and ===
Variables in JS are weak types, and everyone knows it.
var a=3;
var b=”3”;
alert(a==b);
The values of variables in JS are strongly typed. You know.
var a =3;
var b =”3”;
alert(a===b);
They are all variables of type var, but their values are different. One is plastic and the other is string type.
Compared with var type, the var type is of course true, and the ratio of plastic shaping and string shaping is of course false.
== Used to compare whether their values are the same. It will not be a type that calculates the value, as long as their variable is of type var. Of course it's nonsense. Could it be that you can declare variables of the second variable type? .
=== Used to compare, it will determine whether their values are of the same type. If not, there is no comparison. The values of variables in JS are strongly typed, including shaping, strings, numbers, booleans, etc.
and instanceof completed the mission of not being judged
typeof is used to determine basic data types
instanceof is used to determine whether the object type is a certain type number
9.5 inheritances make you feel better.
i. Object impersonation
Circulation method
Usage: Always remember that inheritance in JS is just a copy of properties and methods.
Model structure changes your mind
DOM is a thought, a thought of structuring data in a tree. To learn DOM, you only need to master that any node has a parent node and 0 to more than one child node. Any node has a tag representation on a page and a tag object corresponds to a tag object. The page is just a place to display data, and the memory is the place to save the DOM object data. Any DOM object can only have one parent node object. The father-son relationship can be changed at any time.
must:
Get the object: Check
Object operation: add, repair, delete
Content operation: innerHTML, innerText, etc.
Event operation: mouse, key
Style operation: id, tag, class
Attribute operation: attribute
11. Callback function reduces code writing
What is a callback function?
In JS, function names are used to identify a function. Since we can pass a function name (function handle) to a certain function, and then the function will automatically call our function to complete the relevant processing.
The caller is separated from the callee, and we do not need to care about the caller and the callee. Callbacks can be used for notification mechanisms, events.
12. Functions and arguments
The function name is the handle and pointer of the function. The function name is unique, which also makes it possible that there is no function overload in JS. Only function coverage. The function name uniquely identifies the function.
Always need to be accessed. Function calls in JS are to add brackets after the function name ()
Function call parameters are optional. In any case, the parameters will be stored in the arguments object in the function body. You can use it directly. It is an object, and the parameters are stored in an array.
13. Closures (anonymous functions) open up shortcuts for development
Closures are parameters that call outside the function within a function, and can generally be called anonymous functions, but the two are different.
The value of a closure is that it can be used as a function object or anonymous function. For a type system, this means not only representing data but also code. Most languages that support closures use functions as first-level objects, that is, these functions can be stored in variables and passed as parameters to other functions. The most important thing is that they can be dynamically created and returned by functions.
Anonymous functions reduce conflicts in variable names and provide permission scope for JS without permission scope. When we need to provide an interface but do not want this interface object to be a global variable, we need to use an anonymous function:
(function(){
Local code, externally cannot be accessed unless you provide an entry
})();
JS is a computer programming language, a dynamic language, also known as scripting language, and an analytical programming language. Why scripts? Because it cannot execute itself, it means there is no main function or the entrance to the main program, and it must be parsed and executed by its host environment, that is, the parsing environment. What is analytical type? Because JS does not generate a file in a systematic process such as programming, linking, assembly, etc., and then executes it, it loads and executes it in a string form...
True and false in
empty, null, undefined, false,0,"",'', NaN is all false, and the others are true
3. What is the difference between functions, classes, objects, and constructors?
Answer: In js, functions, classes, objects, and constructors can be said to be no difference. We can say that functions are objects, objects are classes, and classes are constructors. But generally, we call objects an instance of that class, which is to reduce confusion.
Copy the codeThe code is as follows:
function Person(){
}
var person = new Person();
//Person we can call it functions, classes, objects, and constructors (without parameters)
//Person is called a reference to an object
4. Understand this keyword, you understand one-fifth of JS.
This always points to the object that calls the method (function). (must be memorized)
First of all, we need to know what this is?
This is an object in js. It is an object, not a function, this is an object, you can see it as a reference to an object, whom? The object that refers to the calling method.
Where does this object exist? It exists in JS code, generally in functions. If you put this into the <script> tag, you can try window==this, what to print? Why?
Analyze this keywords
Copy the codeThe code is as follows:
function ready(){
alert(this==window);
}
ready();
What to hit at this time? true, why?
Copy the codeThe code is as follows:
function Person(){
='Zhang San';
alert(this==window);
}
new Person();
What to print at this time? false, why?
lengthen the code. Add a var perso=
var person = new Person();
People all over the world know that person refers to the object generated by new Person. new Person creates a JS instance object, and we can bind properties and methods.
Look at the following code
Copy the codeThe code is as follows:
fn=function(){
}
=function(){
alert(this== fn);
}
What to print when () is called? true , why?
Very strange, this is now equal to a function... Why?
Static methods and attributes will help you.
What is static? As the name suggests: it means it is not moving. What is the method of not moving in JS? It means that there is no need to create an instance, you can directly call the method through the class name, without moving anywhere. The method is called. No additional code is required. This is just one-sided statement. The so-called static: is the characteristics of the class that belong to the class itself.
Since classes in Js are objects, why can't they directly bind properties and methods? sure.
Copy the codeThe code is as follows:
fn=function(){
}
='Zhang San';
=function(){
return ;
}
This is OK, but why do you still need the new process? Isn’t it okay to bind it like this? think
The impact of constructor in JS framework
prototype is a prototype and is an object. ,.
The constructor is a constructor, a function
Until now, you have to distinguish clearly when the object is an object and when the object is a function. It is also difficult for JS parser to parse and run such flexible code.
prototype can be said to be a static property of a class, which points to an instance of this object. In other words, prototype is an object. What is the difference between the object pointed to by prototype and the object we have new? An equivalent bridge relationship was established, but not the same. When we bind attributes to the function prototype, the attributes and values are bound to the prototype object, and are not really bound to that object. When you need to access this property on that object, the JS parser will first look for this property from the object itself, and then look for it on the prototype object.
Copy the codeThe code is as follows:
function Person(){
}
var person = new Person();
="Zhang San";
="Li Si";
alert();
delete ;
alert();
The constructor points to an object's constructor. (What is a constructor? Review it yourself.), from this we can see that it is an object-level attribute. That is to use the constructor property, an object must be needed.
So does prototype have constructor attributes for an object? Of course there is, since constructor refers to a constructor, is there a prototype attribute? Of course there is, and so on, the following two codes are correct.
……
……
Actually, I don’t know how long it can be? If you are interested, you can try it. By the way, I'll tell you to use recursive algorithms.
Among many JS code, when we know an object, we ask for its constructor, or we know a constructor, we ask for its object. It should be started.
7.== and==Perform the judgment to the end.
== and ===The appearance of the god is not in appearance. Don’t think about it, you can tell at a glance whether the judgment is equal.
Is there any difference?
==Judge whether the variables are equal.
===Judge the values of variables are equal.
And so on:====What is it used for? ? Used to report an error. You know. I just want to tell you here, only == and ===
Variables in JS are weak types, and everyone knows it.
Copy the codeThe code is as follows:
var a=3;
var b=”3”;
alert(a==b);
The values of variables in JS are strongly typed. You know.
var a =3;
var b =”3”;
alert(a===b);
They are all variables of type var, but their values are different. One is plastic and the other is string type.
Compared with var type, the var type is of course true, and the ratio of plastic shaping and string shaping is of course false.
== Used to compare whether their values are the same. It will not be a type that calculates the value, as long as their variable is of type var. Of course it's nonsense. Could it be that you can declare variables of the second variable type? .
=== Used to compare, it will determine whether their values are of the same type. If not, there is no comparison. The values of variables in JS are strongly typed, including shaping, strings, numbers, booleans, etc.
and instanceof completed the mission of not being judged
typeof is used to determine basic data types
instanceof is used to determine whether the object type is a certain type number
9.5 inheritances make you feel better.
i. Object impersonation
Circulation method
Usage: Always remember that inheritance in JS is just a copy of properties and methods.
Model structure changes your mind
DOM is a thought, a thought of structuring data in a tree. To learn DOM, you only need to master that any node has a parent node and 0 to more than one child node. Any node has a tag representation on a page and a tag object corresponds to a tag object. The page is just a place to display data, and the memory is the place to save the DOM object data. Any DOM object can only have one parent node object. The father-son relationship can be changed at any time.
must:
Get the object: Check
Object operation: add, repair, delete
Content operation: innerHTML, innerText, etc.
Event operation: mouse, key
Style operation: id, tag, class
Attribute operation: attribute
11. Callback function reduces code writing
What is a callback function?
In JS, function names are used to identify a function. Since we can pass a function name (function handle) to a certain function, and then the function will automatically call our function to complete the relevant processing.
The caller is separated from the callee, and we do not need to care about the caller and the callee. Callbacks can be used for notification mechanisms, events.
12. Functions and arguments
The function name is the handle and pointer of the function. The function name is unique, which also makes it possible that there is no function overload in JS. Only function coverage. The function name uniquely identifies the function.
Always need to be accessed. Function calls in JS are to add brackets after the function name ()
Function call parameters are optional. In any case, the parameters will be stored in the arguments object in the function body. You can use it directly. It is an object, and the parameters are stored in an array.
13. Closures (anonymous functions) open up shortcuts for development
Closures are parameters that call outside the function within a function, and can generally be called anonymous functions, but the two are different.
The value of a closure is that it can be used as a function object or anonymous function. For a type system, this means not only representing data but also code. Most languages that support closures use functions as first-level objects, that is, these functions can be stored in variables and passed as parameters to other functions. The most important thing is that they can be dynamically created and returned by functions.
Anonymous functions reduce conflicts in variable names and provide permission scope for JS without permission scope. When we need to provide an interface but do not want this interface object to be a global variable, we need to use an anonymous function:
(function(){
Local code, externally cannot be accessed unless you provide an entry
})();