先上代碼//當對象直接調用這兩個方法的時候,他們的返回結果是一樣的//結果都是 [object Object]var o = {};console.log(o.toString());//=>[object Object]console.log(o.toLocaleString());//=>[object Object]//但是當以call()的方式調用的時候,他們的返回結果發生了改變function foo () { return true;}console.log(Object.prototype.toLocaleString.call(foo));//foo函數轉換成了字符串console.log(Object.prototype.toString.call(foo));//=>[object Function]//而直接用foo調用toString()時,和通過call()調用Object.prototype.toLocaleString()返回的結果一樣console.log(foo.toString());//foo函數轉換成了字符串請問哪位能幫忙講解下,這其中的原理?為什么同樣是調用Object.prototype對象的toLocaleString()和toString(),用在對象上和函數上卻這樣的差異?
Object.toString() 與 Object.toLocaleString() 的區別
烙印99
2018-10-12 10:15:23