gpt4 book ai didi

javascript - 在 underscore.js 微模板中评估数据的不良做法?

转载 作者:行者123 更新时间:2023-12-03 07:09:54 25 4
gpt4 key购买 nike

评估下划线微模板中的数据会产生任何后果吗?

例如,如果我们说我们的 javascript 文件中有这个:

this.template({a: '10'});

在我们的 html 模板文件中

<%= a > 5 ? 'Val is larger than 5':'Val is smaller than 5' %>

不评估模板中的数据会更好吗?

最佳答案

这不是关注点分离的问题吗?您正在将逻辑注入(inject)表示“层”,在我看来,潜在的错误将更难以跟踪。

你的例子很简单,但想象一下你有类似的场景

<%= a > 10 ? (b > 20 ? " and b greater than 20" : " and b less than 20") : ( c > 20 ? " and c greater than 20" : " and c less than 20") %>

完全不可读。

关于javascript - 在 underscore.js 微模板中评估数据的不良做法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36650927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com