说说对react中JSX语法的理解?

什么是JSX?

JSX is an XML-like syntax extension to ECMAScript without any defined semantics. It's NOT intended to be implemented by engines or browsers. It's NOT a proposal to incorporate JSX into the ECMAScript spec itself. It's intended to be used by various preprocessors (transpilers) to transform these tokens into standard ECMAScript.

简单来说,JSX 是类似 XML 的语法的,没有语义的 ECMAScript。它不打算由引擎或浏览器实现。将 JSX 并入 ECMAScript 规范本身也不是一个建议。它的目的是被各种预处理器使用,把语法标记转换成标准的 ECMAScript。


JSX 有三大优点:

快速

JSX 执行更快,因为它在编译为 JavaScript 代码后进行了优化。

安全

与javascript相比,JSX 是静态类型的,大多是类型安全的。使用 JSX 进行开发时,应用程序的质量会变得更高,因为在编译过程中会发现许多错误。它也提供编译器级别的调试功能。

简单

语法简洁,上手容易。

results for ""

    No results matching ""