1

我有一个 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;
}
4

1 回答 1

1

在函数外部声明est_bandwidth变量以使其全局可用。利用var est_bandwidth;

于 2012-12-14T12:24:42.463 回答