因此,我想将object属性(使用Consturctor定义它)添加到这个类中,但是我得到了一个错误。我做错了什么?还有别的办法吗?
class Currency
{
Constructor()
{
/* Properties */
this.ticker = null;
this.name = null;
/* Markets availability */
this.marketBTC =
{
availability: true,
ask: 0.010,
bid: 0.009,
last: 0.010
};
}
}
var a = new Currency();
console.log(a.marketBTC.ask); // error: Cannot read property 'ask' of undefined发布于 2018-05-21 11:15:47
JavaScript区分大小写,它是constructor,而不是Constructor。
见类上的MDN。
https://stackoverflow.com/questions/50447653
复制相似问题