我正在努力將上下文「this」從控制器中的原型函數傳遞到同一控制器中的私有函數(s)。瀏覽器控制檯拋出錯誤「Can not讀屬性'callSomeService'未定義「。我的代碼看起來像 -JavaScript將「this」從原型傳遞到另一個函數
MyController.prototype.somemethod = function(){
return somePrivateFunction()
.then(function (resultsFromsomePrivateFunction){
return someAnotherPrivateFunction(resultsFromsomePrivateFunction)
});
}
function somePrivateFunction(){
this.callSomeService()
.then(function (results) {
return results
});
}
function someAnotherPrivateFunction(){
//dosomething
}
有人可以幫忙嗎?
我沒有在這裏看到任何東西 – Ladmerc
'somePrivateFunction.call(this)'..這個值取決於__how__函數被調用,而不是被__where__函數調用... – Rayon