Platinum Partner

Making The Methods And Properties Lookups Inside A Closure Be Resolved To The Delegate.

// The following code shows how methods and properties will be resolved to the delegate instead of the closure itself.


// creating a closure
def closure = {
    add "groovy"
    add "java"
}

// declaring a list
def list = []

// making the call methods inside closure be resolved to the list
closure.delegate = list
closure.resolveStrategy = Closure.DELEGATE_FIRST

// executing the closure
closure();

// now, the list was changed
list.each { println it }

// output 
// groovy
// java
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}