【译】JavaScript规范译自:https://github.com/airbnb/javascript类型原始值: 相当于传值string
number
boolean
null
undefined
var foo = 1,
bar = foo;
bar = 9;
console.log(foo, bar); // => 1, 9复杂类型: 相当于传引用object
array
function
var foo = [1, 2],
bar = foo;
bar[0] = 9;
console.log(foo[0], bar[0]); // => 9, 9对象使用字面值创建对象// bad
var item = new Object();
// good
var item = {};不要使用保留字reserved words作为键// bad
var superman = {
class: 'superhero',
default: { clark: 'kent' },
private: true
};
// good
var superman = {
klass: 'superhero',
defaults: { clark: 'kent' },
hidden: true
};数组使用字面值创建数组// bad
var it
...
继续阅读
(63)