chiquitinxx / grooscript

Converts your Groovy code to Javascript
https://www.grooscript.org
Other
221 stars 18 forks source link

Advanced scope fails on a closure return #4

Closed chiquitinxx closed 11 years ago

chiquitinxx commented 11 years ago

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 callBackArray[0]() == 3

chiquitinxx commented 11 years ago

Final line is: assert callBackArray[0]() == 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.