【发布时间】:2015-09-28 17:33:51
【问题描述】:
我已经使用 Babel 编译器将 JSX 编译为 JavaScript。这是我感兴趣的一段代码。
getInitialState: function getInitialState() {
//List out different states that ListComponent could possibly have
return {
showList: true,
listType: this.props.type
将 JSX 编译为 JS 后,getInitialState 是一个命名方法 getInitialState()。我不明白为什么它不是匿名方法。
原码:
getInitialState: function() {
//List out different states that ListComponent could possibly have
return {
showList: true,
listType: this.props.type
这样写有性能优势吗?
【问题讨论】:
-
在过去,这使调试更容易。现在调试器足够智能,可以推断名称,请参阅astithas.com/talks/qconsf2013/#/18/2
-
@Oriol 仍然比在整个堆栈跟踪中看到名为匿名的函数要好。 :P
-
@Oriol 对于递归函数或需要内部绑定标识符来引用自身的函数(有点)重要。
-
@Pointy 我假设函数内的代码没有引用该名称。但是,是的,名称函数表达式替换了已弃用的
arguments.callee。 -
所以你显示的是编译后的代码?原始来源是什么?
标签: javascript reactjs react-jsx babeljs