Scope functions apply/with/run/also/let: Where do the names come from?

前端 未结 3 889
梦毁少年i
梦毁少年i 2021-02-01 07:55

There are quite a few blog posts (like this) on usages of the standard library functions apply/with/run/also/let

3条回答
  •  借酒劲吻你
    2021-02-01 08:21

    I strongly recommend to read this blog in order to understand all of these scope functions.

    Some keys of these blog:

    1. LARA functions

    Following the first letter of each, you get the acronym “LARA”.

    1. Code Comparison

    1. Common use cases

      • Transforming an object - let()
      • Create, pass, and evaluate - also()
      • Initialize and execute - run()
      • Initialize an object for assignment - apply()
    2. With

    with() is functionally the same as the extension function version of run(), so it's well-suited to the use case of Initialize and execute. More information.

提交回复
热议问题