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

Support ES6's arrow function? #3620

Closed
AtalisasOwen opened this issue Apr 14, 2017 · 2 comments
Closed

Support ES6's arrow function? #3620

AtalisasOwen opened this issue Apr 14, 2017 · 2 comments

Comments

@AtalisasOwen
Copy link

Description

For example,can I transform test1() to test2()?
function test1() {
$("img").mouseenter(function(e) {
$(this).css("opacity", 0.5);
}).mouseout(function(e) {
$(this).css("opacity", 1.0);
});
}

function test2() {
$("img:odd").mouseenter(e => {
$(this).css("opacity", 0.5);
}).mouseout(e => {
$(this).css("opacity", 1.0);
});
}

Link to test case

@mgol
Copy link
Member

mgol commented Apr 14, 2017

Arrow functions don't have their own this binding so it's technically impossible to use the this binding jQuery provides with an arrow function.

@mgol mgol closed this as completed Apr 14, 2017
@scottgonzalez
Copy link
Member

You can use event.target (or based on the code above, e.target), instead of this though.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants