Check if bound callback method is undefined

Hey folks

Short question. We have a custom element with a callback attribute. This callback attribute might be undefined (generic stuff). Since Aurelia wraps a function around passed value, even if value is undefined, we have no idea how to check it.

// fancy custom element 

export class FancyCustomElement {
  //this guy might be undefined but Aurelia wraps a function which makes it impossible to check if it's undefined.
  @bindable public onChange?: () => void;
<!-- model view -->
//  view model
export class ViewModel {
  public onChange = undefined;

Thanks for your help

Instead of that raise an event on an element and bind a delegate/trigger to it

Or do it with a normal binding (not call).

.bind instead of .call

1 Like

@dweber019 Thanks, seems to work :+1: