You can either initialize the function with canvas by default or provide it as a param, but not both.
var canva = new fabric.Canvas('canvas');
var myComponent = function(canva){
var init = function(){
console.log('init')
}
return{
init:init
}
}(canva);
myComponent.init();
(this variant is useful if your component's consumers/clients do not need to configure the used canvas/dependency)
or
var canva = new fabric.Canvas('canvas');
var myComponent = function(canva){
var init = function(){
console.log('init')
}
return{
init:init
}
};
myComponent(canva).init();
(this variant is useful if your component's consumers/clients need to provide their own parameterized/custom dependency to your component)
function(canva){is an IIFE which returns an Object with a single property, init, which is a function ... note that this means myComponent is the object returned, not a function