Each function not working properly with es6 arrow functions

Description

I faced with problem in each function when using arrow function inside. e.g.

$element
           .parentsUntil($untilElement || 'body')
           .addBack()
           .each(()=>{
          let $this=$(this);
           ...
});

this always referred to last element in the array.

In case of simple array in returns window on this calling.

However, with ES5 regular syntax it is working well

The behavior should be regular to each function

Checked in chrome only

Link to test case

https://jsfiddle.net/16a7nfnu/1/

Author: Fantashit

1 thought on “Each function not working properly with es6 arrow functions

  1. element
        .parentsUntil($untilElement || 'body')
        .addBack()
        .each((i, el) => {
            let $this = $(el);
            ...
    });

Comments are closed.