保留字行为 [英] Reserved Word Behavior
问题描述
在创建一个小柜台基础的游戏,我有一个数组是这样的:
While creating a small counter based game, I had an array like this:
var status = ["day","dusk","night","dawn"];
如果我试图访问数组的第一个指标,我会得到:
If I tried to access the first index of the array, I would get:
console.log(status[0]); //yields "d"
@monners提到这可能是一个保留字,所以我改变了变量名 xstatus
和它工作得很好。
我的问题是:为什么会状态[0]
只返回第一个索引的第一个字母
My question is: why would status[0]
return only the first letter of the first index?
推荐答案
您正在修改对window.status
不能被设置为一个数组:
You're modifying window.status
which cannot be set to an array:
https://developer.mozilla.org/en-美国/文档/网络/ API /对window.status
有是在Firefox中一些无法解释的行为。虽然这两个状态
和 VAR状态
在全球范围内提供给对window.status <引用/ code>属性,
VAR状态
不平整数组:
There is some unexplained behaviour in Firefox. While both status
and var status
at the global scope provide references to the window.status
property, var status
doesn't flatten the array:
status = ["meagar"];
console.log(window.status[0]); // 'm'
VS
var status = ["meagar"];
console.log(window.status[0]); // 'meagar'
这篇关于保留字行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!