コントローラのプロトタイプ関数から同じコントローラ内のプライベート関数にコンテキスト「this」が渡されるのに苦労しています。ブラウザーコンソールは「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