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

Default value expressions in functions have incorrect 'this' #3070

Closed
LPGhatguy opened this issue Dec 22, 2016 · 1 comment
Closed

Default value expressions in functions have incorrect 'this' #3070

LPGhatguy opened this issue Dec 22, 2016 · 1 comment

Comments

@LPGhatguy
Copy link

I'm using this Flow-enhanced JS:

// @flow

class XYZ {
	x = 5;

	show(value: number = this.x) {
		console.log(value);
	}
}

Flow says:

XXX: 	show(value: number = this.x) {
     	                          ^ property `x`. Property cannot be accessed on
XXX: 	show(value: number = this.x) {
     	                     ^^^^ global object

But stripping the types and running this in Chrome works just fine!

class XYZ {
	constructor() {
		this.x = 5;
	}

	show(value = this.x) {
		console.log(value);
	}
}

new XYZ().show(); // 5

In addition, this MDN example seems to note that this should be the function, not the global scope in default parameters.

@danieljuhl
Copy link

Duplicate of #1234

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

No branches or pull requests

3 participants