setup
can.Construct.prototype.setup
construct.setup(...args)
A setup function for the instantiation of a constructor function.
Parameters
-
args
{*}
The arguments passed to the constructor.
Returns
{Array | undefined}
If an array is returned, the array's items are passed as arguments to init. The following example always makes sure that init is called with a jQuery wrapped element:
WidgetFactory = can.Construct.extend({
setup: function(element){
return [$(element)]
}
})
MyWidget = WidgetFactory.extend({
init: function($el){
$el.html("My Widget!!")
}
})
Otherwise, the arguments to the
constructor are passed to init and the return value of setup
is discarded.
Deciding between
setup
andinit
Usually, you should use init to do your constructor function's initialization. Use
setup
instead for:init
method is called.init
methods.init
.Example
This code is a simplified version of the code in can.Control's setup method. It converts the first argument to a jQuery collection and extends the controller's defaults with the options that were passed.