Using ES6 in jQuery

I just learn about ES6 and I was wondering how to use it with jQuery?, so I started to use it.

Here a little sample about how ES6 looks in jQuery, something peculiar that you need to notice is about the property this, remember that is common to use $(this) when want to refer the element itself, well, with ES6 this is not possible, you need to use e.currentTarget instead this.

Here a sample code...

$(document).on('ready',() => {
  const ENV = 'development';

  $('.send-data').on('click',(e) => {
    let $this = $(e.currentTarget);

    // Write here any code that you want to...
  })
})

I will keep updating this post, I know that there is a lot to cover with this topic.

Show Comments

Get the latest posts delivered right to your inbox.