Default parameters work in class methods and arrow functions, but not normal stand-alone functions:
class Foo {
public method(s = "foo") {}
public static staticMethod(s = "foo") {}
}
let baz = (s = "baz") => {};
function bar(s = "bar") {}
Foo = Foo or {}
Foo.__index = Foo
function Foo.new(construct, ...)
local instance = setmetatable({}, Foo)
if construct and Foo.constructor then Foo.constructor(instance, ...) end
return instance
end
function Foo.constructor(self)
end
function Foo.method(self,s)
if s==nil then s="foo" end
end
function Foo.staticMethod(self,s)
if s==nil then s="foo" end
end
local baz = function(s)
if s==nil then s="baz" end
end
;
function bar(s) --s is not initialized here
end
Default parameters work in class methods and arrow functions, but not normal stand-alone functions: