I know the documentation mentions to use .call
when passing functions to a child component, but it seems like I can also use .bind
, is there any reason why I shouldn’t use .bind
? I have a particular use case where I’m generating the callback function and passing that to .bind
now and if its not recommended, not sure how I would do it with .call
.
i.e. (just to paint the picture I know the example is not how you would normally do this)
parent component
items = []
getCallback(index) {
return (value) => {
this.items[index] = value;
}
}
<child-component callback.one-time="getCallback($index)" repeat.for="item of items"></child-component>
child component
@observable model;
@bindable callback;
modelChanged(new,old) {
callback(new);
}