简体   繁体   English

为什么函数不能在我的内部互相调用<app /> React 中的组件

[英]Why can't functions call each other inside my <App /> component in React

I have the following two functions inside my <App /> component and they are placed just before the render() method.我的<App />组件中有以下两个函数,它们位于 render() 方法之前。 I would like open_theme_FUNCTION to be able to call new_or_open_so_clear_workspace_FUNCTION but it is out of scope and not declared.我希望open_theme_FUNCTION能够调用new_or_open_so_clear_workspace_FUNCTION但它超出了 scope 并且未声明。 Why is this?为什么是这样?

    new_or_open_so_clear_workspace_FUNCTION = (that) => {
      that.setState({
        start_show_or_hide : false,
        application_menu_show_or_hide : false,
        workspace_background : "white"
      });
    }

    open_theme_FUNCTION = () => {
      console.log("Opening a project")
      new_or_open_so_clear_workspace_FUNCTION(this)
      // code
    };

I expect it to be a class component, so you only have to use this .我希望它是一个 class 组件,所以你只需要使用this .

open_theme_FUNCTION = () => {
   console.log("Opening a project")
   this.new_or_open_so_clear_workspace_FUNCTION(this)
   // code
};

And you also should avoid passing around this .你也应该避免绕过this Your example should work without doing that.您的示例应该不这样做就可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM