CommandHandler and context menus

Demo: http://codepen.io/anon/pen/rxojXZ

Hi,
I’ve got a context menu that passes in functions of cut copy and paste on a click event, using myDiagram.commandHandler

myDiagram is in scope and is not null, yet I’m getting errors like “this.cutSelection is not a function”, or “Cannot read property ‘selection’ of undefined” while passing the functions as a parameter of another.

var defaultContextMenuButton = function(text, textStyle, myFunction){
return	$("ContextMenuButton", {click: myFunction}
    ....
)}
....
defaultContextMenuButton("Cut", defaultFont, myDiagram.commandHandler.cutSelection);

Any idea why this isn’t working?
Hopefully I’m just being dumb here.

GraphObject.click is a property whose value may be a function that takes two arguments: an InputEvent and the GraphObject where the click function was defined.

CommandHandler.cutSelection is a method that takes no arguments. Methods expect to be called with a binding for this in their body. When it is called as a click event handler, this is not bound to the value of myDiagram.commandHandler.

So you need to call your function in this manner:

defaultContextMenuButton("Cut", defaultFont,
   function(e, obj) { e.diagram.commandHandler.cutSelection(); });

Look at the Basic sample (http://gojs.net/latest/samples/basic.html) for an example of this.