没有箭头反应javascript箭头功能?

Fra*_*cis 1 javascript reactjs arrow-functions slate

我不明白这在javascript中是如何工作的

renderMarkButton(type, icon) {
Run Code Online (Sandbox Code Playgroud)

它看起来像一个箭头功能,但没有箭头.这是上下文:

class HoverMenu extends React.Component {

  renderMarkButton(type, icon) {
    const { editor } = this.props
    return (
      <div className="editorButton" 
            onMouseDown={event => this.onClickMark(event, type)}>
        <FontAwesomeIcon color="#666" active={isActive} 
            className="editorButton" icon={icon}  />
        </div>
    )
  }
  render() {
    return (
      <div>
        {this.renderMarkButton('bold', {...faBold})}
      </div>
    )
  }
}
Run Code Online (Sandbox Code Playgroud)

我也很困惑

  const { editor } = this.props
Run Code Online (Sandbox Code Playgroud)

我相信它来自Slate.我希望this.props在这种情况下是{type,icon}.

bre*_*tex 8

关于你的问题:

  1. renderMarkButton(type, icon) {只是es6类语法:https: //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
  2. const { editor } = this.props被称为"解构".你可以在这里阅读:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment

希望有帮助:)

  • *es6类语法*,它实际上是一个类的方法 (3认同)
  • 类中的方法不需要function关键字. (2认同)