Writing UserTalk scripts without a handler

UserTalk programming tip (via Brent Simmons): If a script has no parameters, it doesn't need a handler method (a method defined with the on keyword that is executed when the script is called).

When a script lacks a handler, the top-level lines of the script will be executed when the script is called with no parameters. The following two versions of a workspace.displayTime script are functionally identical:

on displayTime() {
dialog.alert( clock.now() )
}

dialog.alert( clock.now() )

Add a Comment

All comments are moderated before publication. These HTML tags are permitted: <p>, <b>, <i>, <a>, and <blockquote>. This site is protected by reCAPTCHA (for which the Google Privacy Policy and Terms of Service apply).