标签:des style blog class code java
想了解delete的机制缘起一个现象,我无法解释,也无法理解。
1
2 |
var
x = 1; delete
x; //false |
1
2 |
y = 2; delete
y; //true |
1
2
3
4
5
6
7
8
9
10
11
12
13 |
x = 42; // creates the property x on the global object var
y = 43; // declares a new variable, y myobj = { h: 4, k: 5 }; delete
x; // returns true (x is a property of the global object and can be deleted) delete
y; // returns false (delete doesn‘t affect variable names) delete
Math.PI; // returns false (delete doesn‘t affect certain predefined properties) delete
myobj.h; // returns true (user-defined properties can be deleted) delete
myobj; // returns true (myobj is a property of the global object, not a variable, so it can be deleted) |
特性名 |
说明 |
Configurable
|
设置属性是否可配置,即能否更改(包括名值)或者删除(delect)它,能否修改属性特性等等
|
Enumerable |
设置属性是否可以枚举,即能否通过for-in循环返回
|
Writable |
是否可写 |
Value |
就是属性值,对象在读取属性值时就是从这个位置读取的.
|
1
2
3
4
5
6 |
var
x = 1; Object.getOwnPropertyDescriptor(window, ‘x‘ ); //configurable= false delete
x; //false y = 2; Object.getOwnPropertyDescriptor(window, ‘y‘ ); //configurable= true delete
y; //true |
1
2
3
4 |
function
sum() {} sum = 1; Object.getOwnPropertyDescriptor(window, ‘sum‘ ); //configurable= false delete
sum; //false |
1
2
3
4
5
6 |
Object.defineProperties(window, {sum1:{value:1,configurable: true }}); Object.getOwnPropertyDescriptor(window, ‘sum‘ ); //configurable= true delete
sum1; //true Object.defineProperties(window, {sum2:{value:1,configurable: false }}); Object.getOwnPropertyDescriptor(window, ‘sum‘ ); //configurable= false delete
sum2; //false |
javascript delete机制学习,布布扣,bubuko.com
标签:des style blog class code java
原文地址:http://www.cnblogs.com/xiaoheimiaoer/p/3722071.html