在javascript打印中“document.writeln(Object.prototype);”是什么?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了在javascript打印中“document.writeln(Object.prototype);”是什么?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2034字,纯文字阅读大概需要3分钟。
内容图文
我试过并得到以下输出:
[对象]
我熟悉向Object.prototype添加新函数,以便程序中的每个对象都继承该新函数.但我有点好奇知道这是如何实施的.我猜对象应该是类型
{
name: expression,
name: expression,
...
}
我也猜测Object.prototype应该是其中一个Object属性的关键,该属性的值是'[object Object]’.如果我的理解是正确的,现在请你告诉我吗?
我也想知道'[object Object]’中’object’和’Object’之间的区别是什么.我也想知道上面提到的任何对象是否与前面的’.prototype’有关.你能澄清一下吗?
当我尝试打印Object.prototype.object,Object.prototype.Object,Object.prototype [object],Object.prototype [Object]和Object.prototype [0]时,我总是得到未定义的.如果原型没有任何属性,我怎么得到[object Object]?
解决方法:
对象始终存在,而Object来自[[Class]]内部属性的值,这就是原因
Object.prototype.toString.call([]) === "[object Array]";
Object.prototype.toString.call("") === "[object String]";
Object.prototype.toString.call(new Date) === "[object Date]";
它在15.2.4.2中描述:
15.2.4.2
Object.prototype.toString ( )
# ? ? ?When the
toString
method is called, the following steps are taken:
- If the this value is undefined, return
"[object Undefined]"
.- If the this value is null, return
"[object Null]"
.- Let O be the result of calling ToObject passing the this value as the argument.
- Let class be the value of the
[[Class]]
internal property of O.- Return the String value that is the result of concatenating the three Strings
"[object "
, class, and"]"
.
内部属性有点令人困惑.你可以在8.6.2阅读它们:
This specification uses various internal properties to define the semantics of object values. These internal properties are not part of the ECMAScript language. They are defined by this specification purely for expository purposes. An implementation of ECMAScript must behave as if it produced and operated upon internal properties in the manner described here. The names of internal properties are enclosed in double square brackets
[[
]]
.
顺便说一句,对于jQuery和其他库在其isArray函数中使用了Object.prototype.toString.call技巧,因为所有帧的内部属性都是相同的,即使每个帧都有自己的内置版本的数组.
内容总结
以上是互联网集市为您收集整理的在javascript打印中“document.writeln(Object.prototype);”是什么?全部内容,希望文章能够帮你解决在javascript打印中“document.writeln(Object.prototype);”是什么?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。