Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Advanced scope fails on a closure return #4

Closed
chiquitinxx opened this issue Mar 29, 2013 · 1 comment
Closed

Advanced scope fails on a closure return #4

chiquitinxx opened this issue Mar 29, 2013 · 1 comment
Assignees

Comments

@chiquitinxx
Copy link
Owner

This code fails translating to javascipt:

def getCallBacks(){
def callBackArray = []
def i = 0;
for(;i<3; i++){
callBackArray[i] = {return i;}
}
return callBackArray
}

def callBackArray = getCallBacks()
assert callBackArray0 == 3

@ghost ghost assigned chiquitinxx Mar 29, 2013
@chiquitinxx
Copy link
Owner Author

Final line is:
assert callBackArray0 == 3

Problem was with empty expression in for. Never got before an emptyExpression, now just will return nothing. Javascript and groovy work same way with vars used in closures that are defined outside.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant