As you can see it is possible to reuse the same menu more than once on a page - in the example above it is used as a context menu for each of the "items" (for instance articles or webshop goods). Where ever you insert a "pnformcontextmenureference" you will get a small clickable arrow indicating the menu. Clicking on the reference will bring op the menu.
In your event handler (which defaults to "handleCommand") you should check for both commandName and commandArgument:
The commandName value indicates the menu item which was clicked and the commandArgument is the value set at the menu reference. The use of commandArgument makes it easy to identify which $item the menu was activated for.