I know arrays in javascript are a bit special, compared to other languages, but I don't really get this behaviour, or what's going on here.
I'd like to know why it happens and why I don't get an empty array:
function setupWindowProgBar(settings, window, palette, arr){
console.log('start');
console.log(arr);
if(typeof arr == 'undefined'){
var arr = [];
}
console.log(arr);
console.log('stop');
var arrLen = arr.length;
arr[arr.length] = createProgBar('master', 'bg', window, 0, settings.fillColor, settings.strokeColor, settings.textColor, palette, 'percent', settings.reqType, settings.sourceType, settings.sourceTarget, settings.sourceId);
return arr;
}
produces this in the console:
start
undefined
[]
0:
barType:"master"
bgcolor:"#12181f"
curVal:160
data:
all_goals:160
cost_hours:160
cost_hours_spent:0
cost_money:31610
cost_money_owned:0
parentObj:"progBar"
progress_goals:5
recurring:"no"
wanted_timer:"2018-03-26 05:19:33"
__proto__:Object
fill:"#255f6f"
height:59
maxVal:5
maxWidth:168
sectionHeight:59
stroke:"#7b9dac"
text:"3%"
textColor:"#dee5ed"
textOpt:"percent"
width:200
x:33
y:81
__proto__:Object
height:100
text:"omanko"
length:1
__proto__:Array(0)
stop
I do reckognize the objects in here, but it's not from global pollution as far as I can tell - console.log(window.arr) says that there are no global variables named arr, and I haven't modified the prototype.
Surely, that shouldn't effect a new array declaration anyway?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…