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

Breaks when using ES6 - "this" is no longe referencing the fact within condition or consequence #48

Closed
damianofusco opened this issue May 22, 2016 · 4 comments

Comments

@damianofusco
Copy link

Breaks when using ES6 - "this" is no longe referencing the fact within condition or consequence:

// this breaks and this is an empty object in my case
condition: (R) => {
console.log('this', this); // prints {}
}

// this of course works and this contains my fact
condition: function(R) {
console.log('this', this); // prints the fact
}

@mattbishop
Copy link

+1

@xaricx
Copy link

xaricx commented Dec 13, 2016

+1

Workaround: Remove "=>" syntax and go back to function() for your rules. Example:

condition: function(R){...}

@daxiang28
Copy link

For some reason, the NPM version isn't in sync with the master branch here. The fix from @jaymaycry works. Just install it like so: npm install git://github.com/mithunsatheesh/node-rules.git#master --save

@nikollatesla
Copy link
Collaborator

nikollatesla commented May 15, 2018

Its not possible since we cannot rebind an arrow function. Let us know if you have any alternate thoughts on improving the syntax.

From the Spec:

Any reference to arguments, super, this, or new.target within an ArrowFunction must resolve to a binding in a lexically enclosing environment. Typically this will be the Function Environment of an immediately enclosing function.

http://www.ecma-international.org/ecma-262/6.0/#sec-arrow-function-definitions-runtime-semantics-evaluation

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

5 participants