【发布时间】:2019-04-17 16:17:22
【问题描述】:
我有这个简单的课程:
class myCustomClass{
foo(value){
//do some stuff
}
faa(){
//do some stuff
$.getJSON( someUrl, function(data) {
// how call the method foo(value) here ?
this.foo('fii'); // error occured here, because 'this' is not in 'class' context
}
}
}
当我使用 AJAX 语句时,如何在方法 faa 中使用方法 'foo(value)' ? 我不能在这里使用简单的“this.foo(value)”,因为 AJAX 语句中“this”的上下文不是“类”上下文(而是 AJAX 上下文)
【问题讨论】:
-
来自 c# 我认为您需要在 ajax 调用中实例化该类,然后使用它。
标签: javascript jquery ajax oop