我有一个src js文件,我有这个代码。我需要在脚本中管理est_bandwidth数组,但即使我确定正确的创建我也看不到全局。为什么?如何在函数外部看到数组呢?
var maxBandwidth = 8 * 1024 * 1024; // 8 Mbps
var est_bandwidth = new Array();
function bandwidth(initial_bps, weight_f, weight_s){
this.bps = initial_bps;
this.weight_f = weight_f;
this.weight_s = weight_s;
}
bandwidth.prototype.calcWeightedBandwidth = function(_bps) {
this.bps = parseInt(((this.weight_f*this.bps) + (this.weight_s * _bps))/2)*0.9;
if( this.bps > maxBandwidth && maxBandwidth > 0) this.bps = maxBandwidth;
est_bandwidth.push(this.bps/1024);
return this.bps;
}
答案 0 :(得分:1)
在函数外部声明est_bandwidth
变量,使其在全局范围内可用。使用var est_bandwidth;