Login Register Help
API Documentation
Choose a stylesheet:

Functiondojo.hitch (returns Function)

dojo.require("dojo._base.lang");
Returns a function that will only ever execute in the a given scope. This allows for easy use of object member functions in callbacks and other places in which the "this" keyword may otherwise not reference the expected scope. Any number of default positional arguments may be passed as parameters beyond "method". Each of these values will be used to "placehold" (similar to curry) for the hitched function.
parametertypedescription
scopeObjectThe scope to use when method executes. If method is a string, scope is also the object containing method.
methodFunction|StringA function to be hitched to scope, or the name of the method in scope to be hitched.

Usage

var foo: Function=dojo.hitch(scope: Object, method: Function|String);

Examples

Example 1

dojo.hitch(foo, "bar")();

runs foo.bar() in the scope of foo

Example 2

dojo.hitch(foo, myFunction);

returns a function that runs myFunction in the scope of foo