function test() {
$.ajax({
url:xxx,
type:'GET',
success:function(data) {
data:data;
function employee(data) {
this.customer = function(){console.log(data)}
}
return new employee(data);
}
})
}
var p = new test()
p.customer()//没有找到employee这个方法 想这样调用需要怎么做?
你这个问题有3个问题
1.异步操作后返回结果
2.return返回的其实是success函数,并不是test
3.var p = new test()
前面两个都是undefined的原因
解决办法: