I am using jQuery Widget Factory in my project, and I am trying as much as possible to use ES6 syntax, including arrow functions.
So, how do I reference this
inside the methods of of the widget?
As a hypothetical example, I would like to convert this code
$.widget( "custom.colorize", {
// default options
options: {
red: 255,
green: 0,
blue: 0
},
// The constructor
_create: function() {
this.options.green = 128;
}
});
to this code (note that I changed the _create
function to an arrow function, which will throw an error)
$.widget( "custom.colorize", {
// default options
options: {
red: 255,
green: 0,
blue: 0
},
// The constructor
_create: () => {
this.options.green = 128;
}
});
So, how can I reference the local variables as this is now not pointing to them?
Thanks.