Skip to content

Files

Latest commit

 

History

History
34 lines (25 loc) · 883 Bytes

NestedScopeFunctions.md

File metadata and controls

34 lines (25 loc) · 883 Bytes

Pattern: Use of nested scope function

Issue: -

Description

Although the scope functions are a way of making the code more concise, avoid overusing them. It can decrease your code readability and lead to errors. Avoid nesting scope functions and be careful when chaining them. It's easy to get confused about the current context object and the value of this or it.

Example of incorrect code:

// Try to figure out, what changed, without knowing the details
first.apply {
    second.apply {
        b = a
        c = b
    }
}

Example of correct code:

// 'a' is a property of current class
// 'b' is a property of class 'first'
// 'c' is a property of class 'second'
first.b = this.a
second.c = first.b

Further Reading