【发布时间】:2017-11-25 14:28:58
【问题描述】:
假设我有一堂课
export class PersonName {
constructor(
public firstName: string = "",
public lastName: string = "",
public middleName: string = "",
) { }
}
我想通过在创建对象时传递 json 对象来初始化在构造函数中声明的这些变量。
例如:
var person = new Person({
"firstName" : "abc",
"lastName" : "xyz",
"middleName" : ""
});
【问题讨论】:
-
您的示例不是有效的 JSON(甚至不是有效的语法),您的意思是
:而不是=? -
是的,这只是复制粘贴错误。您对此有什么解决方案吗?
标签: typescript typescript-typings typescript2.0