Clicking application menu items from within an "execute script" action

I make a lot of use of Keyboard Maestro’s Select or Show a Menu item actions, but occasionally, if I’m using a JXA (Yosemite JavaScript) script, its useful to be able to click a menu item from inside the script action, rather than exiting one script and then starting another.

Here is a generic JXA JavaScript function which takes the name of an application and a menu path, and performs a menu-item click.