【发布时间】:2018-07-13 16:08:23
【问题描述】:
如您所见,对象 obj2 正在使用 obj1 中定义的模板字面量。 如何在调用 func() 时更新 obj2 中 title 的对象值?
在文件 1 中
let obj1 = { name: 'abc' },
obj2 = { title : `${obj1.name}` }
在文件2中
import {obj1, obj2} from 'file1';
func();
func() {
let obj1 = _.clone(obj1), obj2 = _.clone(obj2);
obj1.name = 'Title of this Page';
console.log(obj2.title) // Still shows abc
}
【问题讨论】:
-
模板文字不是实时绑定..
-
@Keith - 非常简洁。
标签: javascript string object template-literals