user1903898
user1903898

Reputation: 75

Javascript Global Variable array

I have a src js file where I have this code. I need to manage the est_bandwidth array in the script but even if I'm sure of the correct creation I can't see globally. Why? How can I see the array also outside of the function?

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;
}

Upvotes: 1

Views: 2597

Answers (1)

WTK
WTK

Reputation: 16971

Declare est_bandwidth variable outside of the function to make it available globally. Use var est_bandwidth;

Upvotes: 1

Related Questions