Remove anonymous function creation in "trigger"

Move common code to a private function, in main scope, where it will be
compiled and reused in Crafty.trigger.