What the difference between creating function like these:
[lua]local function foo()
print(“hello”)
end[/lua]
[lua]local foo = function()
print(“hello”)
end[/lua] [import]uid: 54716 topic_id: 10160 reply_id: 310160[/import]
What the difference between creating function like these:
[lua]local function foo()
print(“hello”)
end[/lua]
[lua]local foo = function()
print(“hello”)
end[/lua] [import]uid: 54716 topic_id: 10160 reply_id: 310160[/import]
In the second one, you variable “foo” is only defined at the end of the function, meaning you couldn’t call itself i.e. this wouldn’t work:
local foo = function()
foo()
end
But this would:
local function foo()
foo()
end
It’s important to know the subtle difference as it means, for instance, you couldn’t remove an event listener from itself. i.e. you couldn’t do this with the first version:
[code]
image = display.newImage( “image.png” )
local function onTap( event )
image:removeEventListener( “tap”, onTap )
end
image:addEventListener( “tap”, onTap )
[/code] [import]uid: 5833 topic_id: 10160 reply_id: 37140[/import]