Object對象原型方法調用

hasOwnProperty調用
let obj = {name: '123'}
1.
({}).hasOwnProperty.call(obj,'name')//true
2.
Object.prototype.hasOwnProperty.call(obj,'name')//true
3.
obj.hasOwnProperty('name') //true
toString調用
let obj = {name: '123'}
1.
console.log(({}).toString.call(obj))//[object Object]
2.
console.log(Object.prototype.toString.call(obj))//[object Object]
3.//此方法不穩定,new String,new Number,new Date,new Array有自身的toString不適用
console.log(obj.toString())//[object Object]
相關文章
相關標籤/搜索