Why do I get property of undefined error?

Christopher Jenks

I am getting the following error.

Uncaught TypeError: Cannot read property 'on' of undefined

it happens when I add in the line of code

let ServicePlugin = new ServicePlugin();

Any Idea what I am doing wrong? Below is the full code.

'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;
Quentin Roy

You must provide the learnosity parameter (whatever that is) when you instantiate your class. AnnServicePlugin expects it:

let annServicePlugin = new AnnServicePlugin(learnosity);

Of course, the learnosity object must have the expected on method.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

HotTag

Archive