Javascript JSX 代表什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39461805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does JSX stand for?
提问by user2977636
What does JSX stand for?
JSX 代表什么?
I am referring to the JSX that is defined as a XML-like syntax extension to ECMAScript, which has become quite popular with the increasing popularity of ReactJS.
我指的是 JSX,它被定义为 ECMAScript 的类似 XML 的语法扩展,随着 ReactJS 的日益流行,它变得非常流行。
回答by Andrew Li
JSX stands for JavaScript XML. With React, it's an extension for XML-like code for elements and components. Per the React docs and as you mentioned:
JSX代表ĴAVA小号CRIPT XML。使用 React,它是元素和组件的类 XML 代码的扩展。根据 React 文档和您提到的:
JSX is a XML-like syntax extension to ECMAScript without any defined semantics
JSX 是 ECMAScript 的类 XML 语法扩展,没有任何定义的语义
From the quote above, you can see that JSX doesn't have defined semantics, it's just an extension to JavaScript that allows to write XML-like code for simplicity and elegance, and then you transpile the JSX into pure JavaScript function calls with React.createElement
. Per the React tutorial:
从上面的引述中,您可以看到 JSX 没有定义的语义,它只是 JavaScript 的扩展,允许编写类似于 XML 的代码以实现简单和优雅,然后您将 JSX 转换为纯 JavaScript 函数调用React.createElement
。根据 React 教程:
JSX is a preprocessor step that adds XML syntax to JavaScript. You can definitely use React without JSX but JSX makes React a lot more elegant.
Just like XML, JSX tags have a tag name, attributes, and children. If an attribute value is enclosed in quotes, the value is a string. Otherwise, wrap the value in braces and the value is the enclosed JavaScript expression.
JSX 是将 XML 语法添加到 JavaScript 的预处理器步骤。你绝对可以在没有 JSX 的情况下使用 React,但 JSX 使 React 更加优雅。
就像 XML 一样,JSX 标签也有标签名称、属性和子标签。如果属性值用引号括起来,则该值是一个字符串。否则,将值括在大括号中,该值是包含的 JavaScript 表达式。
Any code in JSX is transformed into plain JavaScript/ECMAScript. Consider a component called Login
. Now we render it like so with JSX:
JSX 中的任何代码都被转换为纯 JavaScript/ECMAScript。考虑一个名为 的组件Login
。现在我们用 JSX 渲染它:
<Login foo={...} bar={...} />
As you can see, JSX just allows you to have XML-like syntax for tags, representing components and elements in React. It's transpiled into pure JavaScript:
如您所见,JSX 只允许您使用类似于 XML 的标记语法,代表 React 中的组件和元素。它被转译为纯 JavaScript:
React.createElement(Login, { foo: ..., bar: ... });
You can read more at the docs.
您可以在文档中阅读更多内容。
回答by nadun
JSXJavaScript stand for syntax extension.It's similar to XML. You can use a simple JSX syntactic transform with React.
JSXJavaScript 代表语法扩展。它类似于 XML。您可以在 React 中使用简单的 JSX 语法转换。
回答by Crzna
JSX - JavaScript Syntax Extension A preprocessor step that adds XML syntax to JavaScript
JSX - JavaScript 语法扩展 将 XML 语法添加到 JavaScript 的预处理器步骤
回答by SANTOSH
JSX stand for Javascript with XML like syntax
JSX 代表具有类似 XML 语法的 Javascript
eg.
<div>
</div>
or <td>
</td>
same like XML format put it in return form in class defined
和 XML 格式一样,把它放在定义的类中的返回形式