转摘JavaScript技巧

文章作者: POPO4J
原文地址: http://www.popo4j.com/article/js-jy.html

JavaScript 可以使用省语句快速创建对象和数组,比如下面的代码:
var car = new Object();
car.colour = 'red';
car.wheels = 4;
car.hubcaps = 'spinning';
car.age = 4;

var car = {
colour:'red',
wheels:4,
hubcaps:'spinning',
age:4
}

对象car就此创建,不过需要特别注意,结束花括号前一定不要加";"否则在IE会遇到很大麻烦。


创建数组的传统方法:

var moviesThatNeedBetterWriters = new Array(
 'Transformers','Transformers2','Avatar', 'rangzidanfei'
);

使用简略语句则:

var moviesThatNeedBetterWriters = [
 'Transformers','Transformers2','Avatar','rangzidanfei'
]

你可能感兴趣的:(JavaScript,html,IE)