javascript中object的运算符操作使用
javascript中object的运算符操作使用
1:delete
使用:
delete obj.x
var obj = {x:1}
obj.x//1
delete obj.x
obj.x//undefined
2:defineProperty
使用:
var obj = {};
Object.defineProperty(obj,"x",{
configurable:false,
value:1
})
delete obj.x //false
obj.x//1
3:in
使用:
window.x = 1;
"x" in window //true
4: instanceof
{} instanceof Object
5: typeof
typeof 123
6:new && hasOwnProperty
function Perosn(){}
Person.prototype.x = 1;
var person = new Person();
person.x //1
person.hasOwnProperty("x")//false
person.__proto__.hasOwnProperty("x")//true
7:this
var obj = {
func:function(){
return this;
}
}
obj.func()//Object()
8:void
void 0 //undefined
void(0) //undefined