Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have been using the following utility function that I wrote a long time ago:</p> <pre><code>/** * @classDescription This class contains different utility functions */ function Utils() {} /** * This method returns a delegate function closure that will call * targetMethod on targetObject with specified arguments and with * arguments specified by the caller of this delegate * * @param {Object} targetObj - the object to call the method on * @param {Object} targetMethod - the method to call on the object * @param {Object} [arg1] - optional argument 1 * @param {Object} [arg2] - optional argument 2 * @param {Object} [arg3] - optional argument 3 */ Utils.createDelegate = function( targetObj, targetMethod, arg1, arg2, arg3 ) { // Create an array containing the arguments var initArgs = new Array(); // Skip the first two arguments as they are the target object and method for( var i = 2; i &lt; arguments.length; ++i ) { initArgs.push( arguments[i] ); } // Return the closure return function() { // Add the initial arguments of the delegate var args = initArgs.slice(0); // Add the actual arguments specified by the call to this list for( var i = 0; i &lt; arguments.length; ++i ) { args.push( arguments[i] ); } return targetMethod.apply( targetObj, args ); }; } </code></pre> <p>So, in your example, I would replace </p> <pre><code>function Field1_Changed(el) { Field_Changed(el, delegate(Agent().Field1_Changed, $j(el).val()), true); } </code></pre> <p>With something along the lines</p> <pre><code>function Field1_Changed(el) { Field_Changed(el, Utils.createDelegate(Agent(), Agent().Field1_Changed, $j(el).val()), true); } </code></pre> <p>Then, inside of <code>Agent().FieldX_Changed</code> I would manually call <code>getApplicationState()</code> (and encapsulate that logic into a generic method to process field changes that all of the <code>Agent().FieldX_Changed</code> methods would internally call).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload