2
次のエラーが発生しています。未定義のエラーのプロパティを取得するのはなぜですか?
Uncaught TypeError: Cannot read property 'on' of undefined
私はコード
let ServicePlugin = new ServicePlugin();
の行に私が間違っているの何任意のアイデアを追加したときにそれが起こりますか?以下は完全なコードです。
'use strict';
class ServicePlugin {
constructor(api) {
this._api = api;
this._api.on('ready',() => this._apiReady());
this._api.on('saveSuccess',() => this._apiSuccess());
}
_apiReady() {
console.log('Plugin Ready')
}
_apiSuccess() {
console.log('Plugin Success');
}
}
let ServicePlugin = new ServicePlugin();
ServicePlugin._apiReady();
module.exports = ServicePlugin;
'new AnnServicePlugin();'あなたはコンストラクタに何を渡しましたか? - '未定義です。 'だから、コンソールはあなたに横たわっていません。単なる 'this._learnosity = undefined;と' on() 'は' undefined'に定義されていません。 – Tushar
「学習」とは何ですか?それはどこに定義されていますか? –
問題は、コンストラクタが引数なしで呼び出されることです。その結果、「学習」は未定義である。 –