【发布时间】:2020-10-30 00:10:29
【问题描述】:
例如
//creating constructor function
function Something(){}
//adding name property to Something prototype
Something.prototype.name='javascript';
是否可以从对象本身访问 name 属性?
//喜欢
Something.name
// but here output will be 'undefined'
// 代码
function Fan(){}
Fan.prototype.speed='high';
Fan.speed
//output of (Fan.speed) undefined
【问题讨论】:
-
请提供您目前拥有的相关代码片段。
-
好吧,
Something.prototype.name。它仅在该类/构造函数的 instances 上从o.name查找到o.prototype.name。 -
您需要在您的问题中添加更多详细信息,说明为什么它不同于“否”,因为您的有限示例似乎已经有了答案。
标签: javascript function inheritance constructor prototype