
-
function
1
2
3
4
5
6
71> function (name,age){
this.name = name;
this.age = age;
}
var person = new Person('xu',27);
var student = { name: 'li',speakEnlish: function(rank){} }; -
Fuction prototype
1
2
3
4
5
6
7
8
9
10
11a> property
Function.arguments 是一个数组
Function.dispalyName
b> method
call
func.call(thisArg, arg1,arg2,...) 作用类似于apply 只是参数不一样
bind
func.bind(thisArg,arg1,arg2...)
apply
func.apply(thisArg, arguments) arguments是可选项,是一个参数数组
thisArg 可以是null -
example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26function printStr(){
console.log("printStr", this.str);
}
var student = {str: "123"}
printStr.bind(student)();
console.log ("printStr prototype",Object.getPrototypeOf(printStr));
function (name,age){
this.name = name;
this.age = age;
}
var person = new Person("xujianhua",23);
console.log("person",person.name);
console.log("person prototype", Object.getPrototypeOf(person));
console.log("person constructor", person.constructor);
// print result
printStr 123
printStr prototype function () { [native code] }
person xujianhua
person prototype {}
person constructor function (name,age){
this.name = name;
this.age = age;
}




近期评论