I try to extend jQuery, but when I call myTest this will return this.myTest.test() is undefined…
can someone tell me why…
(function($) {
$.fn.myTest=function() {
var x=function() {
this.myTest.test();
var b = function() {
this.myTest.coba();
}
}
x();
return this.each(function(){
});
};
$.fn.myTest.test = function(){
alert('test');
};
$.fn.myTest.coba = function(){
alert('coba');
};
$.fn.myTest.iseng = function(){
alert('iseng');
};
})(jQuery);
You call
this.myTest.test();from within the nested functionx. Thusthiswon’t point to the$.fn.myTestobject.You will run into the same problem with
this.myTest.coba();in functionb.To solve that you have to store the context of the
$.fn.myTestobject beforehand to access it: