简体   繁体   中英

TypeError:is not a constructor

i am using tracking.js and i want to create a customTracker so:

var CustomTracker = function(){
  CustomTracker(this, 'constructor');
}

CustomTracker.prototype.track = function(pixel, width, height){

  var results = ['foo'];

  this.emit('track', {
      data: results
  });
}

tracking.inherits(CustomTracker, tracking.Tracker);

var myTracker = new tracking.CustomTracker

myTracker.on('track', function(event) {
  console.log('Event: ', event);
});

tracking.track('#myVideo', myTracker);

But Console says:

Uncaught TypeError: tracking.CustomTracker is not a constructor

Where is the problem. I dont understand why?

Try this (from documentation):

var MyTracker = function() {
    MyTracker(this, 'constructor');
}

tracking.inherits(MyTracker, tracking.Tracker);

var MyTracker = function() {
    MyTracker.prototype.track = function(pixels, width, height) {
        // Your code here

        this.emit('track', {
            // Your results here
        });
    }
}

var myTracker = new tracking.MyTracker();

myTracker.on('track', function(event) {
    // Results are inside the event
});

tracking.track('#myVideo', myTracker);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM