JavaScript:Object.prototype.toString(新数字(5))似乎返回了错误的类型
我正在用Python编写JavaScript解释器,我必须理解其内部结构。考虑这个代码(在V8上测试): 根据报告: 新构造对象的[[Class]]内部属性设置为“Number” 并返回以下各项的组合:JavaScript:Object.prototype.toString(新数字(5))似乎返回了错误的类型,javascript,internal,Javascript,Internal,我正在用Python编写JavaScript解释器,我必须理解其内部结构。考虑这个代码(在V8上测试): 根据报告: 新构造对象的[[Class]]内部属性设置为“Number” 并返回以下各项的组合: "[object ", class, and "]" // where class is the value of [Class]] internal property of O. 因此,为什么返回值是“[对象对象]”,而不是“[对象编号]”?这是V8中的一个bug还是我的理解有误?toStr
"[object ", class, and "]" // where class is the value of [Class]] internal property of O.
因此,为什么返回值是
“[对象对象]”
,而不是“[对象编号]”
?这是V8中的一个bug还是我的理解有误?toString
不接受参数——它是对象上的一个方法。所以如果你打电话
Object.prototype.toString.call(新号码(5))
(从而将号码实例作为this
传递)您将得到预期结果:[Object Number]
当使用参数调用SomeClass.prototype.toString
时,您会得到类似的虚假结果,例如Number.prototype.toString(新编号(5))
将给出'0'
我在node(使用v8)上测试了所有这一切。toString不带参数,你是想做
Object.prototype.toString.call(新号码)
哦,当然对不起,我花了一个小时试图找出我的理解有什么问题,结果只是一个粗心的错误。发生在我们当中最好的人身上:-)
"[object ", class, and "]" // where class is the value of [Class]] internal property of O.