是否有类似 Microsft 的 T4 或类似 ASP.NET 的模板引擎可以在 JS 中编写模板来生成文本(或其他代码)?
例如(其中“<=”表示文本 block 的开始):
<#
...here goes template building code...
for(var i = 0; i < types.length; i++) {
#>
function <#= types[i].name #> () {
}
<#
for(var j = 0; j < types[i].methods.length; j++) {
#>
<#= types[i].name #>.prototype.<#= types[i].methods[j].name #> = function () {};
<#
}
}
#>
澄清:
我想要的是编写与多行文本片段混合的 JavaScript,这是一种比 moustashe.js 等语法更甜美的野兽。
最佳答案
这些被称为 pure javascript engines 。这些天它们似乎不受欢迎。
关于javascript - JS 到文本模板引擎(类似 asp.net),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14336228/