mustache.js中compile(),parse()和render()之间的区别 [英] Difference between compile(), parse(), and render() in mustache.js

查看:106
本文介绍了mustache.js中compile(),parse()和render()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么区别:

Mustache.compile()
Mustache.parse()
Mustache.render()

在新的 mustache.js 版本0.5中。 0,也许对于奖励积分,你可以告诉我们解析和编译之间的区别是什么。

in the new mustache.js version 0.5.0, and perhaps for bonus points you could tell us what the difference between parsing and compiling is in general.

推荐答案

编辑

使用在0.8.0版本中引入的API更改 compile()方法已集成到 parse()。不再需要手动编译模板。

With an API change introduced in version 0.8.0, the compile() method has been integrated into parse(). Manually compiling the templates is no longer required.

Mustache.parse()

语法分析模板并从中创建一个JavaScript函数体(一个字符串)。在此过程中,它会通知模板中遇到的任何语法错误。

Syntactically parses the template and creates a JavaScript function body (a string) from it. During that process it notifies of any syntax errors encountered in the template.

Mustache.compile()

使用从成功的 parse()返回的函数体来创建实际的JavaScript函数。创建的函数放在缓存中以便重复使用。

Uses the function body returned from a successful parse() to create an actual JavaScript function. The created function is placed in a cache for re-use.

Mustache.render()

为给定模板(由 compile()创建的模板)采用适当的函数并将其应用于实际数据。这会创建一个意图显示在屏幕上的结果。

Takes the appropriate function for a given template (the one that was created by compile()) and applies it to actual data. This creates the result meant to be shown on screen.

这篇关于mustache.js中compile(),parse()和render()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆