I want to make object in javascript(like class but it is not support for es5/6 on my browser).My goal is get this of function in callback of Jquery.
Code
var log = e => console.log(e);
$(function(){
var oop = new _oop();
})
var _oop = function(){
this.testVariable = 0;
$.get(url,function(){
log(this.testVariable);//undefined
});
}
That Variable is point at selector by jquery,I could not thought another ideas,just use "var" instead of "this" could deal this.
----supported 2-13----
To satisfy Browser in low level,I can't use arrow function in this case. The above one arrow in my code is for dev-mode.
----supported 2-13---- Fixed it.thx for all. Code
var log = e => console.log(e);
$(function(){
var oop = new _oop();
})
var _oop = function(){
this.testVariable = 0;
var cb = function(){log(this.testVariable);}
$.get(url,cb.bind(this));
}