약속 및 다음 블록에 몇 가지 문제가 있습니다.블록 내의 클래스 함수 사용
기본적으로 다음 블록에서 aFunction(x)
에 액세스 할 수 없습니다.
왜 이런가요? 내 코드는 다음과 같이 보입니다 :
class myClass {
aFunction(x) {
...
}
bFunction(y) {
return new Promise(function (resolve, reject) {
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
resolve(body.token)
} else {
console.log('ERROR: ' + err)
return reject(false)
}
})
}).then(function(res){
this.aFunction(res)
})
}
}
그리고 제가 실제로 약속 블록이 필요한가요?
'this.aFunction (rest)'=>'aFunction (res)'? – marekful