CommandHandler.deleteSelection giving me error

i want to delete the selection on click of a context menu button


upon clicking this delete i get an error

Screenshot%20from%202018-11-01%2014-48-36

The GraphObject.click event handler must be a plain function that takes an InputEvent and the GraphObject as arguments: GraphObject | GoJS API

The CommandHandler.deleteSelection method is a function that is a method, so it expects to be called with this bound to the CommandHandler object.

Clearly you cannot use a method where a plain function is called, because this will not be bound.

click: function(e, button) { 
    e.diagram.commandHandler.deleteSelection();
}

This event handler also avoids the unnecessary closure on myDiagram.

FYI, throughout the GoJS API all event handlers and other functional properties are plain functions that need not expect this to be bound. That permits the free and easy use of arrow functions there and everywhere.

thanx got it