defaults
Byron Murgatroyd edited this page Jan 6, 2019
·
1 revision
Default values can be set on parameters as fallback values on initialisation.
A default can be set from either a value to be substituted or you can pass a function to be executed on instantiation.
class Foo extends MooseJS.defineClass({
final:true,
has:{
classCreated: { is:"ro", isa:Date, required:true, default:new Date() }, // From value
objectCreated: { is:"ro", isa:Date, required:true, default:() => new Date() }, // From function
},
})
{}
When defaulting to a function value you may have to wrap the function itself in an arbitrary wrapper function to stop MooseJS from interpreting it as a function to be executed.
class Bar extends MooseJS.defineClass({
final:true,
has: {
onload: { is:"rw", isa:Function, required:true, default:() => function(){ console.log("I'm the default") } }
}
})
{};