The previous sentence: Mining the boundaries of knowledge, the finer, the depth and breadth of the higher, only the more cattle.
JS's performance has reached one-fifth of Java
(1) = = = = = = = = = = =??
Null = = undefined//true
' = = False//true
Summary = = not reliable, only with = = =
(2) do not use continue;
Low efficiency, Source: JavaScript language Essence 111 pages
(2) var a = {};
a.b= ' xx ';
a[' delete '] = ' yy '; The keywords don't matter.
(3) Delete deletion property
Global variables and local variables cannot be deleted???
var aaaa = 123;
Delete aaaa;
Console.log (AAAA); 123
WINDOW.AAAA = 123;
Delete window.aaaa;
Console.log (WINDOW.AAAA); Undefined
function A () {
var a= 123;
Delete A;
Console.log (a); 123
}a ();
Set as A=null; Pray to Heaven, wait for the garbage collection mechanism to be recycled.
Note: When declaring a variable with VAR, the property created is not configurable, that is, the delete operator cannot be removed
var name=1-No Delete
Sex= "Girl" to delete
THIS.AGE=22-To-remove
(4) typeof instanceof
typeof 2 = = = ' Number '//true
typeof new Number (2) = = = ' Number '//false
typeof ' 2 ' = = = ' String '//true
typeof new String (' 2 ') = = = ' String '//false
typeof true = = = ' Boolean '//true
typeof New Boolean (true) = = = ' Boolean '//false
typeof [] = = = ' object '//true
var a = function () {}; typeof a = = = ' function '; True
[] instanceof Object//true
2 instanceof Number//false
New Number (2) instanceof number//true
var a = function () {}
var B = function () {};
A.prototype = new B ();
New A () instanceof B; True
typeof can judge basic types and function
Instanceof can judge a custom object
Extended Object.prototype.toString.call ([]) = = = ' [Object Array] '; This is the best judgment.
(4) If statement
if (xxxx)? 6 cases of false
Null undefined NaN 0 "false
(4) for in
Traversing objects
Traversing a loose array
var a = new Array (10); a[2]=10; a[5]=10; for (var i in a) {Console.log (i);}
Performance, and did optimize the
var a = new Array (10000000);
a[2]=10;
a[5]=10;
var time1 = new Date (). GetTime ();
for (var i in a) {
Math.random () * MATH.RANDOM () * MATH.RANDOM () * Math.random ();
}
var time2 = new Date (). GetTime ();
for (var i=0; i<a.length; a++) {
Math.random () * MATH.RANDOM () * MATH.RANDOM () * Math.random ();
}
var time3 = new Date (). GetTime ();
Console.log (TIME2-TIME1); ~100ms
Console.log (time3-time2); ~200ms
(5) function literal and function declaration
var a = 2;
function A () {}
Console.log (typeof a); Function? Number?
Summarize:
The declaration of a variable is advanced to the top of the scope, and the assignment remains in place;
The declarative function is "in advance";
function expression only the variable "is advanced", the function is not "advanced";
The declaration of a function has a higher precedence than the declaration of a variable.
Assignments are overwritten according to the order of the front and back!
var a = function () {
Console.log (' AAA ');
}
function A () {
Console.log (' BBB ');
}
var B = function B () {} = = = function B () {}
A ();
(6) Function return value
var a = function (b,c) {
Console.log (b + ', ' +c);
}
Console.log (A ());
(7) This point
function A () {
var = self = this;
THIS.V = ' AAA ';
Function B () {
Console.log (this);
Console.log (THIS.V);
}
b ();
}
New A ();
(8) Arguments
function A (a,b,c,d) {
var args = [].slice.call (arguments);
}
(9) Apply Call
function A () {
Console.log (THIS.X+THIS.Y);
}
A.call ({x:100,y:100});
function C () {
THIS.M = function () {
Console.log (THIS.X+THIS.Y);
}
}
var c = new C ();
C.m.call ({x:100,y:100});
This is the redirect of this, forgive me, can't explain very accurate and easy to understand, can only practise more
(ten) Try catch throw key logic plus just fine
var a = ' AAA ';
try{
A = xxxx (); Methods that do not exist
}catch (e) {
Throw (new error (' Error '));
A = 0;
}
Console.log ("Go Go Go"); Is this the right way???
(11) Closures
for (var i=0; i<2; i++) {
}
Console.log (i);
function A () {
Only the method body has scope
}
var A;
Function C () {
var v = ' VVV ';
Function B () {
return {V:V};
};
A = B ();
}
C ();
Console.log (A.V); The method body is the scope, this everyone knows, the internal method body needs to give a cut out, let outside can access to.
(12) Callback
Function A (callback) {
Callback ();
}
A (function () {
Console.log (' AAA ');
});
(13) Self-executing function, also called self-tuning function
(function (a) {
Console.log (a);
}) (' AAA ');
(14) Regular
var regexp =//img
I case
M line break
G retrieves the first match without stopping, retrieving all
(prototype)
What is prototype?
function A () {
this.v= ' VVV ';
}
Console.log (A.prototype); The current object, the function is also an object,
Console.log (A.prototype.constructor); Current method
Console.log (a.prototype.constructor.__proto__ = = = a.__proto__); True
Prototype is the built-in property of the function, and __proto__ is the built-in property of the object, all of which look for the prototype chain
//prototype usage scenarios?
var b = {};
//function B () {};
//var b = function () {}
b.prototype.bbb= ' BBB ';
console.log (B.BBB);
//console.log (new B (). bbb);//constructor
//prototype how to play? (All of the following are bad usage)
function A () {};
a.prototype = function () {Console.log ("AAA")};
console.log (new A.prototype ());
//function A () {}
//function B () {}
& nbsp; //A.prototype = {aaa: ' AAA '};
//b.prototype = A.prototype;
//var aa1 = new A (),
//AA2 = new A (),
//BB1 = new B ();
//aa1.prototype.aaa= ' xxx ';
//console.log (AA2.AAA);
//console.log (BB1.AAA);
function A () {}
Function B () {this.bbb= ' BBB '};
A.prototype = new B ();
Console.log (New A (). BBB);
-----4 It's actually like this.
Object.create ();
Last Word:!!! Only best technology practices can help!!!
JavaScript Basics (First day)