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

关于this的疑惑 #6

Open
sunnynudt opened this issue Oct 15, 2018 · 0 comments
Open

关于this的疑惑 #6

sunnynudt opened this issue Oct 15, 2018 · 0 comments

Comments

@sunnynudt
Copy link

function foo() {
	var a = 2;
	this.bar();
}

function bar() {
	console.log( this.a );
}

foo(); //undefined

这段代码在chrome控制台执行的时候,不会报错,是可以执行的。
但是在node环境中,是直接报错“TypeError: this.bar is not a function”。
请问,这种情况该如何有效的理解?

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

No branches or pull requests

1 participant