简单的JavaScript数组初始化在Chrome中不工作 [英] Simple Javascript array initialization not working in Chrome

查看:110
本文介绍了简单的JavaScript数组初始化在Chrome中不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做的很简单的东西 - 初始化在Javascript数组。而且它不是谷歌浏览器的工作。这里是code:

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

怎么办?

推荐答案

你的状态变量,冲突与的 对window.status 属性。

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

浏览器只是拒绝进行分配。

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

这篇关于简单的JavaScript数组初始化在Chrome中不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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