forked from VisualCrew/es6-on-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject.es
78 lines (58 loc) · 1.66 KB
/
object.es
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { logStyle } from '../helper/logger.es';
console.log('%cobject.es', 'background-color: #4CAF50; padding: 0 100px; font-size: 32px; color: white;');
if (true) {
logStyle('对象简写');
let a = 'abc';
console.log({
a,
[a]: true,
b() {
// TODO
}
});
}
if (true) {
logStyle('Object.is() 严格比较值的相等');
let obj = { a: 1 };
console.log(Object.is(obj, obj), Object.is(NaN, NaN), obj === obj, obj == obj);
}
if (true) {
logStyle('Object.assign() 浅拷贝对象');
console.log(Object.assign({ a: { a: 1 } }, { a: { b: 2 }}, { a: { c: 3 }}));
}
if (true) {
logStyle('Object.getOwnPropertyDescriptor');
console.log(Object.getOwnPropertyDescriptor({a: 1}, 'a'));
}
if (true) {
logStyle(`属性的遍历(key 为数值&按大小 --> key 为字符串&生成的时间 --> key 为 Symbol 值&生成的时间)
for...in
Object.keys(obj)
Object.getOwnPropertyNames(obj)
Object.getOwnPropertySymbols(obj)
Reflect.ownKeys(obj)`);
}
if (true) {
logStyle('【附录】__proto__ 属性');
logStyle('Object.getPrototypeOf(obj), Object.setPrototypeOf(obj, prototype)');
}
if (true) {
logStyle('Object.keys(obj)');
}
if (true) {
logStyle('【ES7】Object.values(obj), Object.entries(obj)')
}
if (true) {
logStyle('【ES7】rest 解构赋值');
console.log('let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4, c: 5 };');
}
if (true) {
logStyle('【ES7】扩展运算符');
console.log(`
let obja = {};
let objb = {};
let comObj = { ...a, ...b, x: 1 };`);
}
if (true) {
logStyle('【ES7】Object.getOwnPropertyDescriptors(obj)');
}