【发布时间】:2016-05-14 18:01:58
【问题描述】:
在阅读TypeScript handbook 时,我遇到了以下示例:
interface Shape {
color: string;
}
interface Square extends Shape {
sideLength: number;
}
var square = <Square>{};
square.color = "blue";
square.sideLength = 10;
问题是 - 实际上<Square>{} 是什么?对我来说似乎是一个奇怪的语法。从 Java/C# 的角度来看,它就像一个匿名对象的泛型。它究竟是什么,这种创作的局限性是什么?
【问题讨论】:
-
看起来像演员表
标签: javascript object syntax typescript