var obj = {
init:function(){
this.ajax();
},
name:function(){
console.log('123')
},
ajax:function(){
//var _this = this; 不要这种方法,我想要用改变this指向的方法
$.ajax({
url:'http://www.test3.com/Main/isCookie',
method:'GET',
dataType:"jsonp",
jsonp:'jsoncallback',
jsonpCallback:'vv',
success:function(){
console.log( this.name() ) //123
}
})
}
}
obj.init();
如何让我在ajax里的this指向指到obj上?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
使用bind/apply/call或用es6的箭头函数编写
参考这个链接描述