面试题1
var age = 38;
console.log(window);
var obj = {
age: 18,
getAge: function(){
console.log(this.age);
}
}
obj.getAge();
// obj => 18
var f = obj.getAge;
f();
// window => 38
面试题2
var age = 38;
var obj = {
age: 18,
getAge: function(){
console.log(this.age);
function foo(){
console.log(this.age);
}
foo();
}
}
obj["getAge"]();
// 18 38
面试题3
var length = 10;
var age = 18;
function fn(){
console.log(this.length);
}
var arr = [fn, "222"];
fn();
arr[0]();
面试题4
var length = 10;
var age = 18;
function fn(){
console.log(this.length);
}
var arr = [fn,"222"]
fn();
arr[0]();
网友评论