How to extends Backbone.Events

625 Views Asked by At

I am new to Backbone, and asked to add new behavior in a project that was given to me.

I want to extend Backbone Events in order to add some code in trigger and listenTo functions. I found a similar question but when the solution given doesn't work for me.

//My event emitter

var _ = require('underscore');
var Backbone = require('backbone');

const EVENTS = {
 SYNC: 'SYNC',
 BLACK_BG: 'BLACK_BG',
 PLAY: 'PLAY',
 SCROLL_UP: 'SCROLL_UP',
 SCROLL_DOWN: 'SCROLL_DOWN',
};

class EventEmitter {
 constructor() {
  _.extend(this, Backbone.Events);
  this.events = EVENTS;
 }
}


class PromiseEventEmitter extends EventEmitter{
 constructor() {
  super();
 }

 listenTo(object, events, callback) {
  //My code should reach here  
  super.listenTo(object, events, callback);
 }
}

module.exports = new PromiseEventEmitter();

0

There are 0 best solutions below