Don't know the real name for the functionallity in JavaScript, but it's used like this e.g.
1 2 3 4 5 | var myObj = {}; myObj.myVariable = (function()( // .. do stuff return someObj; }()); |
Yes, there is :)
I'll answer this one myself as I just got it to work :)
1 2 3 4 5 6 7 | player.healthBar = (function() local rect = display.newRect(player.x - (player.width / 2), player.y - (player.height / 2) - 8, player.width, 5); rect:setFillColor(0, 255, 0); rect:setStrokeColor(0, 0, 0); rect.strokeWidth = 1; return rect; end)(); |
thanks for sharing.
I'm not sure if anonymous closures get garbage collected well. you're basically creating a new function each time you call .healthBar i think. I don't think that's as optimized as a local setHealth function, but I couldn't say for sure
might be worth doing some tests
j
I have no way of telling if the garbage collector is getting that.
I'm still trying to determine if gcinfo() works in Ansca correctly.
I have no way of telling if the garbage collector is getting that.
I'm still trying to determine if gcinfo() works in Corona correctly.
views:1278 update:2011/10/6 9:28:12