无法填充名为“状态"的数组 [英] Can't populate array called `status`

查看:41
本文介绍了无法填充名为“状态"的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做一些非常简单的事情-用Javascript初始化一个数组.而且它不能在谷歌浏览器中使用.这是代码:

I am trying to do something really simple - initialize an array in Javascript. And it's not working in Google Chrome. Here is the code:

status = [];
for(i=0; i < 8; i++)
  status[i]=false;

alert(status.length); //It says 0 when it should say 8

有什么作用?

推荐答案

status 变量的分配与

The assignment of your status variable, clashes with the window.status property.

Chrome浏览器只是拒绝进行分配.

Chrome simply refuses to make the assignment.

window.status 属性在浏览器底部的状态栏中设置或获取文本.

The window.status property, sets or gets the text in the status bar at the bottom of the browser.

我建议您要么重命名变量,要么使用匿名函数创建新作用域,还记得始终使用 var 声明变量:

I would recommend you to either, rename your variable or use an anonymous function to create a new scope, also remember to always use var for declaring variables:

(function () {
  var status = [];

  for (var i = 0; i < 8; i++)
    status[i] = false;

  alert(status.length);
})();

这篇关于无法填充名为“状态"的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆