1 include(bbq.lang.Watchable); 2 3 bbq.lang.Delegator = new Class.create(bbq.lang.Watchable, /** @lends bbq.lang.Delegator.prototype */ { 4 /** 5 * @type {Object} Holds the options for this object 6 */ 7 options: null, 8 9 /** 10 * @constructs 11 * @extends bbq.lang.Watchable 12 * @param {Object} options 13 */ 14 initialize: function($super, options) { 15 $super(); 16 17 this.options = options ? options : {}; 18 }, 19 20 /** 21 * Example: 22 * 23 * <code> 24 * if(this.willDelegateMethod("foo")) { 25 * return this.delegateMethod("foo"); 26 * } else { 27 * // default action 28 * } 29 * </code> 30 * 31 * @param {String} type 32 */ 33 delegateMethod: function(methodName, args) { 34 if(this.willDelegateMethod(methodName)) { 35 if(typeof(args) == "undefined") { 36 args = []; 37 } 38 39 args.unshift(this); 40 41 return this.options.delegate[methodName].apply(this, args); 42 } 43 }, 44 45 willDelegateMethod: function(methodName) { 46 return this.options.delegate && this.options.delegate[methodName] instanceof Function; 47 } 48 }); 49