// ========================================================================== // Project: SproutCore - JavaScript Application Framework // Copyright: ©2006-2011 Strobe Inc. and contributors. // Portions ©2008-2011 Apple Inc. All rights reserved. // License: Licensed under MIT license (see license.js) // ========================================================================== /** @namespace Support methods for the Delegate design pattern. The Delegate design pattern makes it easy to delegate a portion of your application logic to another object. This is most often used in views to delegate various application-logic decisions to controllers in order to avoid having to bake application-logic directly into the view itself. The methods provided by this mixin make it easier to implement this pattern but they are not required to support delegates. ## The Pattern The delegate design pattern typically means that you provide a property, usually ending in "delegate", that can be set to another object in the system. When events occur or logic decisions need to be made that you would prefer to delegate, you can call methods on the delegate if it is set. If the delegate is not set, you should provide some default functionality instead. Note that typically delegates are not observable, hence it is not necessary to use get() to retrieve the value of the delegate. @since SproutCore 1.0 */ SC.DelegateSupport = { /** Selects the delegate that implements the specified method name. Pass one or more delegates. The receiver is automatically included as a default. This can be more efficient than using invokeDelegateMethod() which has to marshall arguments into a delegate call. @param {String} methodName @param {Object...} delegate one or more delegate arguments @returns {Object} delegate or null */ delegateFor: function(methodName) { var idx = 1, len = arguments.length, ret ; while(idx