-
Notifications
You must be signed in to change notification settings - Fork 0
/
object.js
56 lines (50 loc) · 1.17 KB
/
object.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{
//简洁表示法
let o=1;
let k=2;
let es5={
o:o,
k:k
};
let es6={
o,
k
};
console.log(es5,es6);
let es5_method={
hello:function(){
console.log('hello');
}
};
let es6_method={
hello(){
console.log('hello');
}
};
console.log(es5_method.hello(),es6_method.hello());
}
{
//属性表达式
let a='b';
let es5_obj={
a:'c'
};
let es6_obj={
[a]:'c' //表达式 key值也可以是变量
}
console.log(es5_obj,es6_obj);
}
{
//新增API
console.log('字符串',Object.is('123',123));//三等号
console.log('数组',Object.is([],[]));
console.log('拷贝',Object.assign({a:'a'},{b:'b'}));//浅拷贝 只拷贝自身属性 不可枚举的不可拷贝 引用不拷贝
let test={k:123,o:456};
for(let [key,value] of Object.entries(test)){
console.log(key,value);
}
}
{
// 扩展运算符
let {a,b,...c}={a:'test',b:'kill',c:'ddd',d:'ccc'};
}