// #1 变量{{~ var x = 100}}{{x}}//输出: 100// #2 字符串{{"hello world"}}//输出:hello world// #3 计算输出{{1+2+3}}//输出:6{{100 / 100}}//输出:1{{10 % 3 * 100}}//输出:100// #4 安全输出,对 html 进行 escape{{! "<div> hello world </div>"}}//输出:<div> hello world </div>// #5 强制转换 html 输出{{@ "<div> hello world </div>"}}//输出:<div> hello world </div>
变量定义
// #1{{~ var a =100}}// #2{{~ var a =100,b = 200,c=300}}// #3{{~ let a =100}}// #4{{~ let a =100,b=200,c=300}}// #5{{~ const a =100}}// #6{{~ const a =100,b=200,c=300}}
if-else
// #1{{~ if (x == 100) }}{{~ elseif(x == 200) }}{{~ else if(x == 300) }}{{~ else }}{{~ end }}// #2{{~ if (x == 200) }}output....{{~ /if}}
同时支持 'elseif' 和 'else if'
if 结尾支持使用 {{~end}} 和 {{~ /if}}
for 循环
// #1{{~ for (item of array) }}{{~end}}// #2{{~ for (item in array) }}{{~end}}// #3{{~ for (let item of array) }}{{~end}}// #4{{~ for (const item in array) }}{{~end}}// #5{{~ for (key of Object.keys(item) )}}{{~end}}// #6{{~ for (var x = i;x < 100;x++) }}{{~ end }}// #7{{~ for (item of someMethodInvoke().other()) }}{{~end}}// #8{{~ for (var x = i;x < someMethodInvoke().other();x++) }}{{~ end }}
for 循环结尾支持使用 {{~end}} 和 {{~ /for}}
安全访问
// #1{{a?.b?.c}}// #2{{a.bbbb?().ccc?.ddd}}
递归调用
vartemplate1='{{~for (item of items)}} {{ myRender(item)}} {{~end}}';vartemplate2='{{~for (item of childItems)}} {{ myRender(item)}} {{~end}}';varfasty=newFasty({share:{//自定义你的递归渲染方法myRender:function(data){returnfast.render(data,template2)},}});vardata={items:[{otherAttr:"value1",childItems:[{otherAttr:"value1",childItems:[],},{otherAttr:"value1",childItems:[],},],},{otherAttr:"value1",childItems:[{otherAttr:"value1",childItems:[],},{otherAttr:"value1",childItems:[],},],},],};fast.render(data,template1);
Fasty v1.0.4 发布,一个极快的 JavaScript 模板引擎
Fasty 一个极快的 JavaScript 模板引擎
Fasty 是一个简约、超快的 JavaScript 模板引擎, 它使用了非常独特的缓存技术,从而获得接近 JavaScript 极限的运行性能,并且同时支持 NodeJS 和浏览器。
使用方法
示例1
示例2
Fasty 语法
输出
变量定义
if-else
for 循环
安全访问
递归调用
初始化配置