【发布时间】:2018-04-26 19:20:39
【问题描述】:
我目前在 Typescript 中有一个对象字面量。比如:
const MyNamesStrings = {
a: {
b: "hello",
c: "bye"
}
d: {
e: "qwerty"
}
}
但我想在每次访问它们时将它们包装在一些字符串中。字符串是相同的,如果它在文字中,看起来会非常难看和重复。这将使我能够更轻松地维护字符串。
我想创建一个MyNames 类,它的作用类似于具有执行此功能的代理:
const ab = MyNames.a.b //"[${hello}]" where the extra characters surround the text.
const ac = MyNames.a.c //"[${bye}]"
这在 Javascript/Typescript 中可行吗?如果不是,我总是可以用更平凡的方式来做。
【问题讨论】:
-
以后在 Stack Overflow 上提问前请make some attempt at doing this yourself。
标签: javascript typescript object