Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请写出代码执⾏结果,并解释为什么 #790

Open
lgwebdream opened this issue Jul 6, 2020 · 2 comments
Open

请写出代码执⾏结果,并解释为什么 #790

lgwebdream opened this issue Jul 6, 2020 · 2 comments
Labels
JavaScript teach_tag

Comments

@lgwebdream
Copy link
Owner

function fn() {
  console.log(this.length);
}
var person = {
  length: 5,
  method: function (fn) {
    fn();
  },
};
person.method(fn, 1);
@lgwebdream lgwebdream added the JavaScript teach_tag label Jul 6, 2020
@lgwebdream
Copy link
Owner Author

扫描下方二维码,获取答案以及详细解析,同时可解锁800+道前端面试题。

@kuckboy1994
Copy link

这题考的是this的指向问题

1 当做函数调用的时候,指向window

2 对象方法调用的时候,指向调用对象

3 通过call,apply使用的时候,指向传入的第一个参数

4 构造函数创建实例对象的时候,构造函数内的this指向实例对象

function Fn(){
    this.user = “111”;
}
var a = new Fn();
console.log(a.user); //111

5 箭头函数的this,指向调用环境中的this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JavaScript teach_tag
Projects
None yet
Development

No branches or pull requests

2 participants