On Mon, May 3, 2010 at 10:24, Daniel Wagner <[email protected]> wrote:

> Hi Burak,
>
> Martin agrees it shouldn't be a big deal to add a context parameter, so
> feel free to open a bug report.
>
> In the mean time, you can use qx.lang.Function.bind to set the context
> of your validator function.
>

And if you find yourself using the static method qx.lang.Function.bind(...)
a lot and would prefer to be able to just say this.bind(...) you use this
code in your applicaiton:

      // Add a bindTo() method to qx.core.Object as a shortcut to constantly
      // having to use qx.lang.Function.bind()
      qx.Class.include(qx.core.Object, custom.MObject);

Here's the actual mixin to add to your project:

/* ************************************************************************

   Copyright:
     2009 Derrell Lipman

   License:
     LGPL: http://www.gnu.org/licenses/lgpl.html
     EPL: http://www.eclipse.org/org/documents/epl-v10.php
     See the LICENSE file in the project's top-level directory for details.

   Authors:
     * Derrell Lipman (derrell)

************************************************************************ */

/**
 * Mixin to add a bindTo method to qx.core.Object
 */
qx.Mixin.define("custom.MObject",
{
  members :
  {
    /**
     * Bind a function to this object
     *
     * @param func {Function}
     *   The function to be bound
     *
     * @param varargs {Any?}
     *   Optional arguments to be passed to the function.
     *
     * @return {Function}
     *   A wrapped version of the function that binds 'this' to the
     *   user-provided function.
     */
    bindTo : function(func, varargs)
    {
      return qx.lang.Function.create(
        func,
        {
          self  : this,
          args  : (arguments.length > 1
                   ? qx.lang.Array.fromArguments(arguments, 1) :
                   null)
        });
    }
  }
});
------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to