dojo.delegate
<script src="../../js/dojo.js"></script>
defined in dojo/_base/lang.js
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.
Usage
function (obj, props) (view source)
parameter | type | description |
---|---|---|
obj | object to delegate to for properties not found directly on the return object or in props. | |
props | object containing properties to assign to the returned object |
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