js advanced reference document

javascript Features:

1 explained interpreted slow line one line; one-time compiler implementation code is compiled into executable code, then performing the fast line by line; 2 flexible and dynamic characteristics of the object can take to add attributes and methods; 3 JavaScript function first-class functions citizenship; 4 execution environment of the host environment;

Object: a memory area containing data and code; properties and methods;

Object-oriented: the idea of the design process.
How the real world things actually exist, use the code in the form of show.

Three characteristics: encapsulation, inheritance, polymorphism (abstract);

Object-oriented way:
creating a template for creating an object (instance instance);
template to create objects in JavaScript is the constructor;

Create Object:
. 1: new new Object ();
2: = {} var Hero; object literal;
3: Factory function to create a plurality of functions;
4: Constructor;

Constructor:
name of the first letter capitalized;
1 creates an empty object in memory;
this 2 set by the constructor, just to make this point to create a good object;
3 to execute code in the constructor;
4 returns the object;
5 not acquired using a specific type of object typeof;
6 specific type of acquisition targets: .constructor;
. 7 determines whether or not an object is an instance of a constructor / objects: instanceof;

:( instance members object members) member associated with the object, the object for future use way to call;

Static members: members are members of a property or method of the object constructor;

Prototype: Prototype created by the method, constructor creates all objects are accessible;
.prototype (each constructor has a property, prototype object);
Student.prototype.sayHi = function () {
the console.log ( 'Hello everyone, I am a' + this.name );
};

当调用对象的属性或者方法的时候,先去找对象本身的属性/方法 ,如果对象没有该属性或者方法。此时去调用原型中的属性/方法;如果对象本身没有该属性/方法,原型中也没有该属性或者方法,此时会报错;

Constructor has a property in the prototype object constructor function;
constructor functions: recording the created object constructor, the object is created record constructor;

Relationship: constructor prototype object instance / object s1 proto relationship between the
constructor has the prototype object,
create an object instance of the constructor, each object will have a prototype property (. Proto ), the prototype property points to this structure prototype object function, prototype object in a a constructor property, the constructor property will refer back to it in the constructor, we create the constructor this object, it and there was a (. proto ) property, each object has __proto__ the property that points to the object constructor function of the prototype;

Prototype chain:
Each object has properties __proto__; __proto__ prototype object Object object point is obtained;
prototype object prototype object refers to null;
if the object itself prototype method, the nearest call;

Precautions:
Under normal circumstances, the properties of an object in the constructor to set up, methods of an object in the prototype object constructor to set up, when we change the prototype constructor when the need to re-set constructor property, use Object Access prototype object constructor is used to create the object constructor, set to go prototype property, and then create the object, the members can access the prototype object;
Student.prototype = {
constructor: Student,
the sayHi: function () {
the console.log ( 'the sayHi')
},
EAT: function () {
the console.log ( 'EAT');
}
};

render: Rendering;

bind:
a new method, bind the first parameter may vary as a function of this is directed; bind returns by a new function;
bind and no method is called;
var A = 123;
function Fn () {
the console.log (this.a);
}
window.fn (); 123 //
var o = {a: 'ABC'};
var = Fn1 fn.bind (o); fn method of the window is equal to bind to the variable o , i.e. o.fn (), then the new variable fn1 receiving
fn1 (); // abc corresponds o.fn (); i.e. window.fn ();

Calling a function from:
; (function (window, undefined) {
the console.log (XX)
}) (window, undefined)
must be preceded by a semicolon, to avoid calls from two binding functions;
passing window parameters of the object and two undefined It is to allow variable names can be compressed;

Inheritance:
members of the replicated object to another object
for (var Key in WJL) {
// do not give the same name as the attribute copy wsc
IF (wsc [Key]) {
Continue;
}
wsc [Key] = WJL [Key];
}

Prototypal inheritance:
inheritance: relationship between type and type;
inheritance purposes: handle common types of members of the extract to the parent type, code reuse;
prototypal inheritance: Unable to set the parameters of the constructor;

This refers to the function change:
Call (): a list of parameters when the transfer parameters are passed;
1: to change the function of this, direct call function;
2: The first parameter is the change of this point, the latter parameter is a property ;
3: call return value is the return value of the function;
fn.call (obj, 5, 6); (who put the call who wrote in .call front);
uses: methods of any objects can be directly used by call with;
front point is a function is called, the first parameter is a function of that object to invoke

apply(): 在传递参数时,接收的是一个数组;会把数组拆开传递;
	 只有两个参数
		1: 调用函数,改变函数中的this;
		2: 第一个参数  设置函数内部this的指向;
	  	    第二个参数  是数组;
		3: 函数的返回值 apply的返回值就是函数的返回值;
	fn.apply(obj, [1, 2]);
	用途:通常用于数组的解包;

bind(): 
		1: 改变函数中的this,不会调用函数,而是把函数复制一份;
		2: 第一个参数 设置函数内部this的指向;
	    	    其它参数,对应函数的参数;
		3: 函数的返回值 call的返回值就是函数的返回值;
	var f = fn.bind(obj, 5, 5);
		f();
	用途:在函数中的函数,如果要使用外层函数中的this时,可以在里层函数最后面加上bind(this),这样在里层函数中就可以使用外出层函数的this对象;

Borrowing constructor:
function object execution method call, passing an object, the current role is to function as a method of an object called directly;

Inheritance composition:
borrow constructor + prototype inheritance;
function parent (parent parameter) {
the this attribute = parent parameter;.
}
Parent.prototype

Defined function:
the old versions of IE, if the function declaration statement will lift;
1 function declaration
function Fn () {
the console.log ( 'Test');
}
Fn ();

 2 函数表达式
		var fn = function () {
		console.log('test');
		};

3 new Function()
	函数也是对象
	var fn = new Function('var name = "张三";console.log(name)');
		fn();

Function call:
// this refers to a normal function call window
// function Fn () {
// the console.log (this);
//}
// window.fn ();

// 2 方法调用     this指向调用该方法的对象
// var obj = {
//   fn: function () {
//     console.log(this);
//   }
// }
// obj.fn();

// 3 作为构造函数调用   构造函数内部的this指向由该构造函数创建的对象

// 4 作为事件的处理函数   触发该事件的对象
// btn.onclick = function() {
//   console.log(this);
// }  

// 5 作为定时器的参数   this指向window
// setInterval(function () {
//   console.log(this);
// }, 1000);

Summary: inside a function this, by the time a function call to determine its points;

Internal function has a private variable: arguments; when the number of arguments is not fixed, when the internal function, the parameters can be acquired through actual arguments passed over;

Higher-order functions:
1 function as a parameter:

2 函数作为返回值的时候:	

Closure:
There are two scopes, scopes in the inner layer of the outer layer if you want to use the variable scope, this variable will not end with the destruction and the destruction of outer scope, but remains some scope for the inner layer time, until the outer scope executed, before destruction, variables and functions in the outer layer to form a closure together;

Recursion:
function calls itself; conditions are generally required to write an end of;
Case:
use recursion to achieve + 2 + 3 + 1 + 4 ... + the n-
function GetSum (the n-) {
// recursive end condition
if (n == . 1 =) {
return. 1;
}
return GetSum n-+ (n--. 1);
}

		console.log(getSum(3));
	第一次执行的时候 n=3 ,也就是 3+getSum(3 - 1),但是getSum(3 - 1)是个调用函数,会再次执行调用,同时此次函数还得到保留, 此时getSum里已经是2了,也就是n=2,会再次执行函数,也就是2+getSum(2-1);这是getSum里面 的n已经是1了,然后再次执行,n=1满足判断条件就向上返回1,也就是2+getSum(2-1),这里(2-1)可以看做n;最后一次的返回值是1,那么2+getSum(2-1)也就是2+1;然后最后一次的执行就会释放不再保留,现在的返回值也就是2+1,会返回给3+getSum(3 - 1);也就是3+2+1,所以最后返回值为6;

Copy of the object:
wrapper function - the member of o1, copied to O2
function Copy (o1, O2) {
for (var Key in o1) {
O2 [Key] = o1 [Key];
}
}
Copy (OBJ1, obj2);

浅拷贝:只拷贝对象的第一层属性,如果修改被拷贝的对象,复制后的对象的值修改后不会变,方法会变;
深拷贝:拷贝对象的多层属性,

Regular expression:
action: the string processing;
meta characters:
\ D match numbers;
\ D except matching numeric characters (spaces, symbols); \
W alphanumeric underscore (not including Chinese characters); \
W is in addition to alphanumeric underline;
\ S matches a space and a newline;
\ S except spaces and line breaks;
matched any single character (excluding line feed);.
^ in who started;
$ ending who;
qualifier:
\ D * defined in the preceding characters appear zero and multiple (several are OK); \
d + preceding character limit appears once and several times;
\ d? Defining preceding character appear zero and one;
\ D {n} matches the preceding character appears n times;
exact match ^ \ D {n} Katex the parse error: the Expected 'the EOF', GOT '\ D' AT position. 11:; n bit digital; \ d {nm} matches at least the front of the digital ... ; n bits to m bits between;
\ D {n,} matching number appears in front of at least n times is not limited;
exact match ^ \ d {n }; at least n bits;
special characters:
[AC] matches characters a to c;
[^] matches all characters except inside the brackets;
\ escape;
(a | B) a or B;
use:
The RegExp (); first parameter: pattern; Second Argument: i ignore case global matching g;
create objects manner:
var = XXX / ab & [AZ] / I;
.test: matching;
.onkeyup keyboard bounce ;
.onchange changed;
.onblur lost focus;
.exec extraction; (extract a)
.match :( extracting a plurality of extraction)
.replace replacement;
.split cut into an array;
.search
packet extracting: RegExp ($ 1), RegExp ( $ 2) ...

Guess you like

Origin blog.csdn.net/weixin_44260420/article/details/93721631