📜  反应应该在功能组件或外部功能组件中编写方法 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:03:34.242000             🧑  作者: Mango

代码示例1
In most cases you should declare the functions outside of the component function
so you declare them only once and always reuse the same reference. When you 
declare the function inside, every time the component is rendered the function 
will be defined again.

There are cases in which you will need to define a function inside the component
to, for example, assign it as an event handler that behaves differently based on
the properties of the component. But still you could define the function outside
Ball and bind it with the properties, making the code much cleaner and making 
the update or draw functions reusable.