let func1 = () => {
console.log(this);
}
func1();
console.log('end');
let obj = {
test:()=>{
return this;
}
, test1:function(){
return this;
}
}
obj.test() == obj; // false
obj.test1() == obj; // true
íĻėę° íļėķëë ë°Đėė ë°ëž thisę° ëŽëžė§ëëĪ.
Function.prototype.apply()
function introduce(a, b) {
console.log('ėë
ëīėīëĶė '
+ this.name
+ 'ęģ ëėīë '
+ this.age
+ 'ėī ėīėž ėëķííī');
console.log(a);
console.log(b);
}
var person = {
name: 'ëŊžėĢž'
, age: 20
}
introduce.apply(person, [123, 234])
// ėë
ëīėīëĶė ëŊžėĢžęģ ëėīë 20ėī ėīėž ėëķííī
// 123
// 234
function introduce(a, b) {
console.log('ėë
ëīėīëĶė '
+ this.name
+ 'ęģ ëėīë '
+ this.age
+ 'ėī ėīėž ėëķííī');
console.log(a);
console.log(b);
}
var person = {
name: 'ëŊžėĢž'
, age: 20
}
introduce.call(person, 123, 234)
// ėë
ëīėīëĶė ëŊžėĢžęģ ëėīë 20ėī ėīėž ėëķííī
// 123
// 234
function introduce(a, b) {
console.log('ėë
ëīėīëĶė '
+ this.name
+ 'ęģ ëėīë '
+ this.age
+ 'ėī ėīėž ėëķííī');
console.log(a);
console.log(b);
}
var person = {
name: 'ëŊžėĢž'
, age: 20
}
let func1 = introduce.bind(person, 123, 234);
func1();
// ėë
ëīėīëĶė ëŊžėĢžęģ ëėīë 20ėī ėīėž ėëķííī
// 123
// 234