javascript - 如何使用参数调用返回的函数?Javascript
问题描述
所以我在 react 中做了一个编辑器,并添加了一些额外的工具,所以我需要根据所选项目更改工具栏。
在此方法只有一个工具栏之前:
bottomToolbar.updateToolbar( nodeattrs.align,
nodeattrs.fontFamily,
nodeattrs.fontSize,
nodeattrs.fill,
nodeattrs.stroke,
nodeattrs.strokeWidth )
但是新的工具栏有不同的参数,它只需要 4 个参数。
没有我的新工具栏会根据其状态呈现正确的工具栏,我希望类方法 updateToolbar 根据正在呈现的工具栏进行更改,因此我可以跳过检查所选工具栏的 if 评估,我不想每次调用 updateToolbar 时都检查它。
switch(this.state.selectedToolbar){
case "SelectorAndText":
return <TextBottomToolbar
ref={this.bottomToolbarRef}
fontSizeUpdater = {this.fontSizeUpdater}
fontColorUpdater = {this.fontColorUpdater}
strokeColorUpdater = {this.strokeColorUpdater}
strokeSizeUpdater = {this.strokeSizeUpdater}
fontFamilyUpdater = {this.fontFamilyUpdater}
alignmentUpdater = {this.alignmentUpdater}
/>
break
case "FreeLine":
return <LineBottomToolbar
ref={this.bottomToolbarRef}
strokeColorUpdater={this.updateStrokeColor.bind(this)}
strokeSizeUpdater={this.updateStrokeSize.bind(this)}
shadowColorUpdater={this.updateShadowColor.bind(this)}
shadowSizeUpdater={this.updateShadowSize.bind(this)}
/>
break
正如你所看到的,我有一个对应工具栏的引用,所以我想用伪代码调用该方法,如下所示:
updateToolbar(){
//return selectedToolbarRef.current.updateToolbar
}
因此,当我在 bottomtoolbar.updateToolbar(bla, bla, bla) 或 .updateToolbar(bla, bla) 外部调用时,它使用返回的函数
编辑:一种方法是
bottomToolbar.updateToolbar()(bla,bla) but the function that updateToolbar returns it's a method that uses **this**, if I call it like that it's undefined
*在评论中解决
解决方案
推荐阅读
- angular - 使用角度在剑道树视图中附加自定义节点
- java - 使用 ExoPlayer 2.8 播放播放列表中的特定文件
- react-native - redux-observable 您在预期流的地方提供了“未定义”
- android-things - 如何在 Android Things 控制台上注册和识别单个设备或我们如何让设备进入通道
- xamarin - Xamarin.iOS:如何更改工具栏中图像的大小
- java - 使用 Scanner 扫描另一个类中的预定义字符串列表,并将它们解析为 java 中的 Ints
- javascript - navigationOptions 没有在标题上显示我的按钮
- html - 如何避免内嵌图标跳转到移动设备的下一行?
- python - 嵌套循环跟踪
- php - 从数据库中查找的最小日期