- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
从 Chrome 中的 javascript 控制台:
> function Person(name){this.name=name;}
undefined
此时,根据 Javascript 规范,Person.prototype 应该是一个空对象。让我们分配它:
> p=Person.prototype
> Person
请注意,> Person 是可点击的,它会扩展为:
constructor: function Person(name){this.name=name;}
__proto__: Object
但是……它不应该是一个空对象吗?什么是所有额外的东西?如果您发出警报:
alert(p)
你得到 [object 对象]。为什么,当您在 Chrome 控制台中键入它时,会出现 > Person 展开?这不是一个空对象吗?
谢谢!
最佳答案
不,prototype
始终具有 constructor
属性,该属性指向作为其原型(prototype)的函数。当然它也继承自一个对象,即内部 __proto__
属性。
它在 ECMAScript 5 Section 13.2, Creating Function Objects 中定义:
(...)
16. Let proto be the result of creating a new object as would be constructed by the expression
new Object()
whereObject
is the standard built-in constructor with that name.17. Call the [[DefineOwnProperty]] internal method of proto with arguments
"constructor"
, Property Descriptor {[[Value]]: F, { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}, and false.18. Call the [[DefineOwnProperty]] internal method of F with arguments
"prototype"
, Property Descriptor {[[Value]]: proto, { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false}, and false.(...)
这意味着:
创建一个名为 proto 的新空对象 (16)。在该对象上定义属性 constructor
并将值设置为 F(函数本身)(17)。然后在函数 F 上定义属性 prototype
并将其值设置为 proto。
如果您警告
一个对象,那么该对象将被转换为一个字符串。默认行为是将对象转换为 [object Object]
字符串,除非“特殊”toString
方法被覆盖。
Chrome 控制台列出了这些属性,因为它用于调试,因此您需要信息。 [object Object]
信息量不大。
FWIW,一个空对象看起来像这样:
您还可以在此处查看内部 __proto__
属性。空对象总是继承一些默认属性,但它没有自己的属性。
关于javascript - Chrome 的 Javascript 控制台 : what does it output in terms of objects?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6553951/
我遇到了随机森林抛出错误的问题。 我有这个数据框,其中包含已经采用矩阵形式的推文数据,其中包含我试图预测的情绪列。 'data.frame': 1000 obs. of 2155 variabl
在 ansi-term 和 multi-term 中,在我 cd 到一个目录后,我收到一条错误消息和乱码输出,其中 ls 的内容打印但与提示重叠。这是我得到的 $ cd /Users/crippled
我是否必须设置诸如.emacs.d/init_bash.sh之类的东西(对于shell模式),或者它可以读取我的~/.bash_profile直接地?如果是后者,如何设置配置 ansi-term/mu
我有一个类似这样的查询 select city_desc from mst_city where upper(city_desc) like upper('%branch%') 它填充结果以分支开头的
在这里,我试图获取多个术语的搜索结果。说 fulltext="Lee jeans",然后 regexresult={"lee","jeans"}。 代码: IProviderSearchContext
我有一个看起来像这样的方法: public void UpdateTermInfo(List termInfoList) { foreach (Term termInf
With your perfect help here我已经了解了如何计算热门话题(标准分数 + float 平均值)。 我的下一个问题:我的数据库中的术语(由 1-3 个单词组成)与它们被提及的时间
我需要有目的地再创建 2 个表:一个表将存储标签和类别数据(类别可以有层次结构,但标签没有),另一个表存储标签、类别和内容之间的关系。但我对那两张 table 的名称很困惑。我确实是网络开发的新手。经
我在 Elasticsearch 文档 (6.8) 中看到了关于跨度查询的部分, 请求和结果类似于一些术语级别的查询,但它提到跨度是“低级别位置”,闻起来更像是偏好(也许我错了)。 问题是如果我想使用
我在使用 Solr 4.2.0 的“/terms”请求处理程序方面遇到困难。 使用 Web 浏览器,以下 url 返回 fieldName INDUSTRY 的术语列表 http://localhos
我目前正尝试在 elasticsearch 中做一些有趣的事情……而且它几乎可以工作。 用例:我必须将每个特定字段的结果数限制为 (x) 个结果。 示例:在餐厅的结果集中,我只想为每个餐厅名称返回两个
在 term.el ,我们可以从一种子模式更改为另一种子模式。但是,有没有办法用一个功能(和一个键绑定(bind))在它们之间切换? 另一个问题:有没有办法在term-char-mode 中用键盘标记
我有一个按以下顺序列出的员工姓名和薪水列表 我需要按以下格式创建输出表。即,每当累计工资总额超过 3000 时,我必须检测到并标记该行。 我试图做 row_cumsum 并在它超过 3000 时重置
当使用 eshell 或 ansi-term 和 bash emacs 时,会根据您所在的目录更改默认目录变量。 因此,如果我移动到 /home/user/code/project,然后使用 ido-
我可以在我的数据集上使用 R 包“e1071”运行 svm,但我无法使用任何两个预测变量绘制图形。即使谷歌搜索了很多,我也无法找到它的解决方案。请高手帮我解决这个问题: 我有一个具有以下属性的数据集:
Term::ReadLine::Stub::new(/usr/lib/perl5/5.8.8/Term/ReadLine.pm:243): 我期待看到Term::ReadLine::new ,这通常是
我要搜索这个: Post Cereal 得到这个: Post Honey Nut Cereal 通配符是空格。 我知道我可以执行 SPLIT 和一系列 AND 和 Contains() 并将每个术语作
我想根据聚合数据在换句话说过滤数据中放置一个条件。 目前,我有一个查询 GET sense/_search { "size": 0, "aggs": { "dates": {
我在一个围绕化学式的项目上遇到了麻烦。我有两个类(class),Term 和 Formula。 Term 接收诸如“H”或“C2”之类的输入 - 只有一个字母和任意数量的后续数字。它的字段是 elem
我尝试使用 boost::numerics::odeint 来积分微分方程组。我的代码是 dMat Equation::solveODE(dMat u_i, double t_i) { dVec u_
我是一名优秀的程序员,十分优秀!