不带箭头的javascript箭头函数?
我不明白这在javascript中是如何工作的不带箭头的javascript箭头函数?,javascript,reactjs,arrow-functions,slate,Javascript,Reactjs,Arrow Functions,Slate,我不明白这在javascript中是如何工作的 renderMarkButton(type, icon) { 它看起来像一个箭头函数,但没有箭头。以下是上下文: class HoverMenu extends React.Component { renderMarkButton(type, icon) { const { editor } = this.props return ( <div className="editorButton"
renderMarkButton(type, icon) {
它看起来像一个箭头函数,但没有箭头。以下是上下文:
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>
)
}
}
我相信这是来自石板。在这种情况下,我希望this.props是{type,icon}。关于您的问题:
renderMarkButton(类型,图标){
只是es6类的语法:
const{editor}=this.props
被称为“destructuring”。您可以在这里阅读:希望对您有所帮助:)关于您的问题:
renderMarkButton(类型,图标){
只是es6类的语法:
const{editor}=this.props
被称为“destructuring”。您可以在这里阅读:希望对您有所帮助:)这是一种特殊的语法,根据new
class
关键字,它将允许您创建类
基本上,这些都是该特定类的方法,您不能使用该特定语法定义该类之外的任何其他方法
有关更多信息,请参见。这是一种特殊语法,它根据new
class
关键字创建类
基本上,这些都是该特定类的方法,您不能使用该特定语法定义该类之外的任何其他方法
有关详细信息,.Arrow和bound方法可用于将它们作为回调传递给以后调用:
<Component onClick={this.clickHandler}/>
renderMarkButton
是类原型方法。它不像arrow函数那样工作,因为它没有绑定到上下文。使用错误的上下文调用它会导致错误,因为没有此。props
对象:
const unboundFunction = this.renderMarkButton;
unboundFunction('bold', {...faBold});
Arrow和bound方法对于将它们作为回调传递给以后调用非常有用:
<Component onClick={this.clickHandler}/>
renderMarkButton
是类原型方法。它不像arrow函数那样工作,因为它没有绑定到上下文。使用错误的上下文调用它会导致错误,因为没有此。props
对象:
const unboundFunction = this.renderMarkButton;
unboundFunction('bold', {...faBold});
renderMarkButton
是一个类方法,并且const{editor}=this.props
正在使用“destructuring”检索this.props.editor
renderMarkButton
是一个类方法,const{editor}=this.props
正在使用“destructuring”检索this.props.editor
。es6类语法,它实际上是一个类的方法类中的方法不需要函数关键字。@breytex他如何访问this.props
该渲染器按钮中的?@MaheerAlithis.props
和this.state
>在每个react组件中都是全局可用的。请阅读此处:)@breytex Thankses6类语法,它实际上是一个类的方法类中的方法不需要function关键字。@breytex如何访问这个。在renderMarkButton
里面的props
?@MaheerAli这个。props
和这个.state
是在每个react组件中都有全球可用。请在此处阅读更多:)@breytex谢谢