我使用构造函数方法在Javascript中定义了一个类Timeline,
function Timeline(formal parameters)
{
//property definitions
}
这些方法是在原型对象上定义的,
Timeline.prototype.zoomMax = function(){ // Method Definition };
我正在使用数组来存储时间轴的对象,
var timeline = [];
timeline[0] = new Timeline(parameter's values);
timeline[1] = new Timeline(parameter's values);
但是当我调用 Timeline 的方法时,
timeline[0].zoomMax();
我收到错误,
未捕获的类型错误:无法读取未定义的属性“zoomMax”
注意:我已经检查了打印时间线 [0],对象正在存储在其中。
当我将对象存储在一个简单的变量而不是数组中时,它可以正常工作,
var timeline = new Timeline(parameter's values);
timeline.zoomMax(); //Gives me the output
我没有得到,如何对存储在数组中的对象调用方法 zoomMax()。
请指导。
我的时间线代码,
function Timeline(video_duration_in_sec,frames_per_sec = 25,zoom_value=1){
ComponentContainer.call(this,'time-cover');
this.video_duration_in_sec = video_duration_in_sec;
this.frame_count = video_duration_in_sec * frames_per_sec;
this.zoom_value = zoom_value;
this.ruler_width = this.video_duration_in_sec * (100/this.zoom_value);
this.min = 1;
this.max = 25;
}