为什么构造函数第一次工作然后返回typeerror?

时间:2018-04-15 18:04:06

标签: javascript javascript-objects

我有一个构造函数来创建一个对象。我第一次打电话给它,我没有错误,一切正常。我第二次调用它时出现以下错误:

这是调用构造函数的地方:

$('#start_realtime_tracking').click( function() {

//first, clear out any previous layers
clearLayers();
clearInterval(updatePositions);

//initial the tracking variables to clear out any last usage
aircraftTracking = [];
callSigns = [];
devID_query = [];

console.log('controller-1049: start RealTime Tracking');

// First, get a list of the aircraft we will be tracking
var i =0;
$.each($("input[class='form-check-input callSign_checkbox-rt']:checked"), function () {
  var aircraft = new aircraftObj( $(this).prop('value'), $(this).prop('id'), new Date(), getPolycolor($(this).prop('value')) );
  aircraftTracking.push( aircraft );
  callSigns.push( $(this).prop('value') );
  imeis.push( $(this).prop('value') );
  //console.log('adding callsign ', $(this).prop('value'), ' i= ', i++);
});

imeis在全球范围内定义。这是构造函数本身:

function aircraftObj (imei, callSign, timeStart, color) {
  console.log('aircraft Constructor: ', imei, ' , ', callSign, ' , ', 
                timeStart, ' , ', color );
  this.imei = imei;
  this.callSign = callSign;
  this.currentPosition = L.latLng[0,0];
  this.previousPosition = L.latLng[0,0];
  this.alt = 0;
  this.speed = 0;
  this.azimuth = 0;
  this.attribute - [];
  this.positions = [];
  this.startMarker = 0;
  this.endMarker = 0;
  this.flightMarker = 0;
  this.polyline = [0,0]; // list of all polylines.
  this.polyColor = color.replace('0x', '#');
  this.moving = 0;
  this.trackedFromStart = 0;
  this.markerColor;
  this.firstMovement = timeStart;
  this.lastMovement = timeStart;
  this.tmpmarker1 = 0;
  this.tmpmarker2 = 0;
};

我没有记录任何其他错误,因此我不认为内存已损坏,但显然,某些事情正在发生。我该如何追踪这个?

这是错误:

controller.js:1327 Uncaught TypeError: aircraftObj is not a constructor
    at HTMLInputElement.<anonymous> (controller.js:1327)
    at Function.each (jquery.min.js:2)
    at HTMLButtonElement.<anonymous> (controller.js:1326)
    at HTMLButtonElement.dispatch (jquery.min.js:3)
    at HTMLButtonElement.q.handle (jquery.min.js:3)
 (anonymous) @ controller.js:1327
 each @ jquery.min.js:2
 (anonymous) @ controller.js:1326
 dispatch @ jquery.min.js:3
 q.handle @ jquery.min.js:3
 controller.js:1736 

0 个答案:

没有答案