我正在使用tracking.js,我想创建一个customTracker,所以:

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);


但是控制台说:


  未捕获的TypeError:tracking.CustomTracker不是构造函数


问题出在哪里。我不明白为什么?

最佳答案

试试看(从文档):

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);

09-27 13:27