Javascript consuming variables when variable a = variable b

I have a script setup like this (http://jsfiddle.net/YD66s/): var countFull = new Array(0,1,2,3,4,5,6); var countActive = new Array(0,1,2,3,4,5,6); function pickRandom(a) { if(arguments[1].length == 0) { arguments[1] = arguments[0]; } var m = Math.floor(Math.random()*arguments[1].length); chosen = arguments[1].splice(m,1); return chosen; } setInterval(function() { pickRandom(countFull,countActive); }, 1000); When I run this I want the variable to be set for that function only. Instead it is affecting countFull towards the end because I make arguments[1] = arguments[0]. How in javascript can I just reference a variable but not consume it and ultimately arguments[1] becomes arguments[0]. Hope this makes sense. This is driving me nuts how different javascript variables are compared to other languages like PHP.

以上就是Javascript consuming variables when variable a = variable b的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏