Lucius's Blog

JavaScript之二 - 表达式

1. delete

1
2
3
4
5
6
7
8
9
10
11
12
var obj = {x:1};
obj.x; // 1
delete obj.x;
obj.x; // undefined

var obj1 = {};
Object.defineProperty(obj1, "x", {
configurable: false, // configurable为false表示该值无法删除
value: 1
});
delete obj1.x; // false
obj1.x; // 1

2. in

1
2
window.x = 1; //全局变量
"x" in window; // true

3. new

1
2
3
4
5
6
function Foo(){}
Foo.prototype.x = 1;
var obj = new Foo();
obj.x; // 1
obj.hasOwnProperty("x"); // false
obj.__proto__.hasOwnProperty("x"); // true

4. this

1
2
3
this; // window
var obj = {fun:function() { return this; }};
obj.func(); // obj

5. void

1
2
void 0; // undefined
void (0); // undefined
我只是试下能不能被赞赏😳