[英]Javascript Global Variable array
我有一個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;
}
在函數外部聲明est_bandwidth
變量以使其全局可用。 使用var est_bandwidth;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.