javascript - Migrating EventEmitter to ES6 -


i'm getting error gettoken undefined when called below , after transpiling gulp-babel. moving constructor bottom of class not either. can advise?

i think has util inheriting, may trying take es5 code , apply area es6 things differently?

var events = require('events'); var util = require('util'); class report {      constructor(private_key, service_email, debug) {         this.private_key = private_key;         this.service_email = service_email;         this.debug = debug || false;          events.eventemitter.call(this);          this.gettoken( (err, token) => {             if (err) throw err;              return this.emit('ready');         });     }      gettoken(cb) {         ...     } }  util.inherits(report, events.eventemitter);  module.exports = report; 

judging call events.eventemitter in constructor, using this:

require('util').inherits(report, events.eventemitter); 

this breaks report class (not sure why, can reproduce problem).

instead, use es6-style inheritance:

class report extends events.eventemitter {    constructor(private_key, service_email, debug) {     super();     ...   }     gettoken(cb) { ... } } 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -