About RegisterEventListener in Custom Dockers

Is there any way to register an event listener with function in second parameter? For example, like this:

class MyClass {
  constructor() {
    this.onSelectionChange = this.onSelectionChange.bind(this);
    this.subscribe();
  }
  subscribe() {
    window.external.RegisterEventListener(
      'SelectionChange',
      this.onSelectionChange
    );
  }
  onSelectionChange() {
    alert('onSelectionChange');
  }
}
new MyClass();

Or string is the only way?