Login Register Help
API Documentation
Choose a stylesheet:

Functiondojo.delegate

dojo.require("dojo._base.lang");

This is a small implementaton of the Boodman/Crockford delegation pattern in JavaScript. An intermediate object constructor mediates the prototype chain for the returned object, using it to delegate down to obj for property lookup when object-local lookup fails. This can be thought of similarly to ES4’s “wrap”, save that it does not act on types but rather on pure objects.

parametertypedescription
objTheobject to delegate to for properties not found directly on the return object or in props.
propsanobject containing properties to assign to the returned object

Usage

var foo=dojo.delegate(obj: The, props: an);

Examples

Example 1

var foo = { bar: "baz" };
var thinger = dojo.delegate(foo, { thud: "xyzzy"});
thinger.bar == "baz"; // delegated to foo
foo.thud == undefined; // by definition
thinger.thud == "xyzzy"; // mixed in from props
foo.bar = "thonk";
thinger.bar == "thonk"; // still delegated to foo's bar