the wrong and wrong in 1.JS
JS is a computer programming language, is a dynamic language also known as scripting language, is a analytic programming language. Why the script? Because he is not able to perform, there is no main function or the main program of the portal, must be his hosting environment, that is, parsing the environment to execute him. For what is the analytic type? Because JS will not be programmed, linked, assembly and other systems of the process to generate a file, and then execute, he is loaded as a string execution.
true and False in 2.JS
Empty, null,undefined,false,0, "", ", Nan are all false, the other is true
3. What is the difference between a function, a class, an object, or a constructor?
A: In JS functions, classes, objects, constructors can say that there is no difference, we can say that the function is both object, object is both class, class is both constructors. But in general, we call the object an instance of that class, which is to reduce clutter.
Copy Code code as follows:
function person () {
}
var person = new person ();
Person we can call functions, classes, objects, constructors (without parameters)
A reference to person as an object
4. Understand this keyword, you know JS one-fifth.
This always points to the object that called the method (function). (Must back)
First you know what this is?
This is an object in JS. is an object, not a function, this is an object you can look at as a reference to an object, who does it refer to? Refers to the object that invokes the method.
Where does this object exist? The existence of JS code, generally exists in the function. If you put this in the <script> tag, you can try Window==this, print what?
Profiling this keyword
Copy Code code as follows:
function Ready () {
alert (This==window);
}
Ready ();
What are you playing at this time? True, why?
Copy Code code as follows:
function person () {
This.name= ' John ';
alert (This==window);
}
New Person ();
What do you print at this time? False, Why?
Add the code a little longer. Add a var perso=
var person = new person ();
People all over the world know that person refers to the object that the new person produces. The new person creates a JS instance object, and we can bind the properties and methods.
Look at the code below.
Copy Code code as follows:
Fn=function () {
}
Fn.ready=function () {
Alert (this== fn);
}
What is printed when Fn.ready () is invoked? True, why?
Very strange, this is now equal to a function. Why?
static methods and properties in 5.JS will help you..
What is static. As implies meaning: is not moved, JS in the method is not moving? Just because you don't need to create an instance, you can invoke the method directly through the class name without moving anywhere. method is invoked. No additional code is required. This is only a one-sided statement. The so-called static: is a class belongs to the characteristics of the class itself.
JS in the class is object, why not directly binding properties and methods. Of course.
Copy Code code as follows:
Fn=function () {
}
Fn.name= ' John ';
Fn.getname=function () {
return fn.name;
}
This is OK, but why do you want the new process, all this binding is not OK? Thinking
The influence of 6.prototype and constructor in JS framework
Prototype is a prototype and is an object. ,。
Constructor is a constructor and is a function
Until now, you need to be clear about when objects are objects and when objects are a function. Also hard to JS parser, can be resolved to run so flexible code.
Prototype can say that he is a static property of a class, and he points to an instance of this object. In other words prototype is an object. What is the difference between the object that prototype points to and the object we new? An equivalent bridge relationship is established, but not the same one. When we bind a property to a function prototype, the attribute and value are bound to the prototype object, and there is no real binding to that object. When you need to access this property on that object, the JS parser first goes to the object itself to find the attribute, and then to the prototype object.
Copy Code code as follows:
function person () {
}
var person = new person ();
Person.name= "John";
Person.prototype.name= "Dick";
alert (person.name);
Delete Person.name;
alert (person.name);
Constructor point to the constructor of an object. (What is a builder?) Go over your own review. , which can be seen as an object-level attribute. That is, to use the constructor attribute, you must need an object.
So prototype is an object with no constructor attribute? Of course, since constructor refers to the constructor, is there a prototype attribute? Of course, and so on, the following two pieces of code are correct.
Constructor.prototype.constructor.prototype.constructor ...
Prototype.constructor.prototype.constructor.prototype ...
In fact, I do not know how long can I even? Interested to try. By the way, let me tell you the recursive algorithm.
In a lot of JS code, when we know an object, ask his constructor, or know a constructor, ask his object. should be getting started.
7.== and = = will judge in the end.
= = = and = = The idol is not like. Do not consider, at a glance to see whether the fault is equal.
Is there a difference between wood?
= = Determine whether variables are equal.
= = = Determine the value of the variable is equal.
And so on: = = = = = for what?? It's for the error. You know. Here just want to tell you, only = = = =
The variables in JS are weakly typed and are understood.
Copy Code code as follows:
var a=3;
var b= "3";
alert (A==B);
The value of a variable in JS is strongly typed. You know.
var a = 3;
var B = "3";
alert (A===B);
are variables of var type, but their values are different, one is reshaping, and the other is string type.
The Var type and the Var type, of course, are true, and the shape and string ratios are, of course, false.
= = To compare whether their values are the same. Will not be the type of value, as long as their variable is var type can be. Of course, this nonsense, you can not declare the second variable type of variable?
= = = = To compare, to determine whether their values are of the same type. If not, there is no comparison. The values of the variables in JS are strongly typed, with shaping, strings, numbers, Boolean, and so on.
8.typeof and Instanceof completed their mission of Judgment .
typeof used to judge basic data types
Instanceof is used to determine whether an object type is a class model
9.5 kinds of inheritance to make you a menace ..
I. Object posing
Ii.apply
Iii.call
Iv.prototype
V.for Cycle mode
Usage: Always just keep in mind that the inheritance in JS is just a copy of the properties and methods.
10.DOM model structure to change your mind
Dom is a thought, a thought that takes data in a tree-like structure of data. Learning Dom only needs to master that any one node has a parent node and 0 to many child nodes. Any node has a label representation on a page and a memory corresponding to a Label object. The page is just a place to show the data, where the DOM object data is stored in memory. Any DOM object can have only one parent node object. A parent-child relationship can change at any time.
Have to:
Getting objects: Checking
Object manipulation: Add, repair, delete
Content operation: Innerhtml,innertext, etc.
Event Action: Mouse,key
Style action: Id,tag,class
Attribute actions: Attributes
11. Callback function reduces code writing
What is a callback function?
In JS, the function name is used to identify a function. Both we can pass to a function name (function name handle), and then by that function to automatically call our function to complete the relevant processing.
The caller is separated from the callee, 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 of the function, the pointer, the function name is unique, which also makes the JS has no function overload. Only function overrides. The function name is the one that uniquely identifies the function.
Always need to visit, the function call in JS is the function name after the parentheses ()
The function call parameter is dispensable, in any case, the parameter will be stored in the function body of the arguments object, you can directly use him, he is an object, parameters are stored as an array.
13. Closure (anonymous function) opens up a shortcut for development
A closure is an argument outside of a function called a function, and is generally called an anonymous function, but the two are different.
The value of closures is that it can be a function object or an anonymous function, which means not only representing the data but also representing the code for the type system. Most languages that support closures use functions as first-level objects, meaning that they can be stored in variables, passed as arguments to other functions, and, most importantly, can be created and returned dynamically by functions.
Anonymous functions reduce the conflict of variable names and provide permission scopes for JS that does not have permission to scope. Anonymous functions are required when we need to provide an interface, but we do not want this interface object to be a global variable:
(function () {
Local code, external can never be accessed unless you provide an entry
})();