init
can.Construct.prototype.init
Called when a new instance of a can.Construct is created.
construct.init(...args)
Parameters
-
args
{*}
the arguments passed to the constructor (or the items of the array returned from setup)
If a prototype
init
method is provided, it is called when a new Construct is created, after setup. Theinit
method is where the bulk of your initialization code should go, and a common thing to do ininit
is to save the arguments passed into the constructor.Examples
First, we'll make a Person constructor that has a first and last name:
Then we'll extend Person into Programmer and add a favorite language:
Modified Arguments
setup is able to modify the arguments passed to
init
. If you aren't receiving the exact arguments as those passed tonew Construct(args)
, check to make sure that they aren't being changed bysetup
somewhere along the inheritance chain.