| 96 | // |
| 97 | // The output would be "b1", "a2". |
| 98 | function delegateMethod(delegator, delegatee, methodName) { |
| 99 | var inherited = delegator[methodName]; |
| 100 | delegator[methodName] = function() { |
| 101 | var target = delegatee; |
| 102 | var method = delegatee[methodName]; |
| 103 | |
| 104 | // The method doesn't exist on the delegatee. Instead, |
| 105 | // call the method on the delegator, if it exists. |
| 106 | if (!method) { |
| 107 | target = delegator; |
| 108 | method = inherited; |
| 109 | } |
| 110 | |
| 111 | if (method) { |
| 112 | return method.apply(target, arguments); |
| 113 | } |
| 114 | }; |
| 115 | } |
| 116 | |
| 117 | // Implement a vague facsimilie of jQuery's data method |
| 118 | function elementData(el, name, value) { |