【发布时间】:2020-06-24 07:59:44
【问题描述】:
!((
input,
processed = {
foo: 1,
...input
}
) => {
window.console.log(processed)
})({
bar: 2 // input configuration
})
被缩小到:
((t, e = {
foo: 1,
bar: 2
}) => {
window.console.log(e);
})();
我需要 input 参数以供以后配置
问题:如何保持原有的格局?
我需要的 Terser 输出:
((t, e = {
foo: 1,
...t
}) => {
window.console.log(e);
})({bar: 2});
评论后更新:
let input1 = { bar:2 }
!((
input,
processed = {
foo: 1,
...input
}
) => {
window.console.log(processed)
})( input1 )
输出:
((t, e = {
foo: 1,
...t
}) => {
window.console.log(e);
})({
bar: 2
});
【问题讨论】:
-
无论你做什么,你什么时候做的都应该照顾好?从当前代码中,只有一个常量作为参数传递,而 terser 正在内联它。如果将来您在函数内更改此参数,则 terser 应该认识到这一点并且不再内联。 (请记住,扩展运算符无论如何都会进行浅拷贝。因此需要在嵌套对象中发生更改以反映在
input和processed参数中。) -
Tnx,这是指向答案的指针;我在所有更简洁的配置选项中都进行了错误而漫长的搜寻。将我的补充复制粘贴到答案中,我可以将其标记为已回答。
标签: ecmascript-6 spread-syntax terser