JSX 只是类似 HTML 的标记还是周围的代码?

Is JSX just the HTML-like markup or the surrounding code as well?

我有一个术语问题。假设我有以下代码:

var Name = React.createClass({
  render: function() {
    var ranNum = Math.round(Math.random() * 200);

      return (
        <p>
          Hello, {ranNum}!
        </p>
      );
    }
});

当人们谈论 JSX 时,它只是 return 中的 HTML 类项目吗?还是像 ranNum declaration/initialization?

一样也包括周围的 JavaScript

从阅读文档(和提议的规范扩展)来看,JSX 似乎只是类似于 HTML 的语法。它周围的其他一切都很普通 JavaScript.

谢谢,

基鲁帕

From reading the docs (and the proposed spec extension), JSX seems like it is just the HTML-like syntax. Everything else around it is just plain JavaScript.

是的。 JSX 只是 JavaScript 语法的 扩展 。来自 spec:

JSX is a 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.