有人可以为一个人提出“无法读取未定义的属性'推动”的光线,我的技能是有限的。
function Position(position) {
if (!position) {
throw new Error('No position object given!');
}
this.lat = parseFloat(position.lat);
this.lon = parseFloat(position.lon);
this.timestamp = position.timestamp;
this.heading = position.heading;
this.speed = position.speed;
};
Position.prototype.getLatLng = function () {
return new L.LatLng(this.lat, this.lon);
};
function Positions(positions) {
if (!(positions instanceof Array)) {
throw new Error('No positions array given!');
}
for (var i = 0; i < positions.length; i++) {
this.positions.push(new Position(positions[i]));
}
};
答案 0 :(得分:2)
this.positions 未在此功能中定义。尝试在推送操作之前定义它。
this.position = [];
答案 1 :(得分:0)
尝试
for (var i = 0; i < positions.length; i++) {
positions.push(new Position(positions[i]));
}