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]

猜你喜欢

转载自blog.csdn.net/m0_37285193/article/details/118940751