What is the best passing to functions - variables or arrays/objects?

前端 未结 2 455
走了就别回头了
走了就别回头了 2021-01-23 12:51

What is the best practice regarding passing data to functions - variables, or arrays(objects).

For example, I need user info for most functions. Should I pass full user

2条回答
  •  猫巷女王i
    2021-01-23 13:06

    There's no better practice for all scenarios. Use either one depending on the purpose of your function:

    • You may pass the values of individual object properties if your function doesn't care about the object.

    • You should pass the object if your function is going to manipulate the object in some way, either by directly modifying its properties or by calling its methods.

提交回复
热议问题