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
| var person = { a: 1, b: 2, c: 3, }; console.log(person);
Object.defineProperty(person, 'a', { value: 4, writable: true, configurable: true, enumerable: true, }); console.log(person);
Object.defineProperty(person, 'a', { value: 4, writable: false, configurable: true, enumerable: true, }); person.a = 8; console.log(person);
Object.defineProperty(person, 'b', { configurable: false, });
delete person.a; delete person.b; console.log(person);
Object.defineProperty(person, 'c', { enumerable: false, });
for (var key in person) { console.log('列舉 =>', key); }
|