API Docs for: 0.0.1
Show:

File: src/js-ext/lib/function.js

/**
 *
 * Pollyfils for often used functionality for Functions
 *
 * <i>Copyright (c) 2014 ITSA - https://github.com/itsa</i>
 * New BSD License - http://choosealicense.com/licenses/bsd-3-clause/
 *
 * @module js-ext
 * @submodule lib/function.js
 * @class Function
 *
*/

"use strict";

require('polyfill/polyfill-base.js');

var NAME = '[Function]: ';

(function(FunctionPrototype) {
    /**
     * Sets the context of which the function will be execute. in the
     * supplied object's context, optionally adding any additional
     * supplied parameters to the end of the arguments the function
     * is executed with.
     *
     * @method rbind
     * @param [context] {Object} the execution context.
     *        The value is ignored if the bound function is constructed using the new operator.
     * @param [args*] {any} args* 0..n arguments to append to the end of
     *        arguments collection supplied to the function.
     * @return {function} the wrapped function.
     */
    FunctionPrototype.rbind = function (context /*, args* */ ) {
        console.log(NAME+'rbind');
        var thisFunction = this,
            arrayArgs,
            slice = Array.prototype.slice;
        context || (context = this);
        if (arguments.length > 1) {
            // removing `context` (first item) by slicing it out:
            arrayArgs = slice.call(arguments, 1);
        }

        return (arrayArgs ?
            function () {
                // over here, `arguments` will be the "new" arguments when the final function is called!
                return thisFunction.apply(context, slice.call(arguments, 0).concat(arrayArgs));
            } :
            function () {
                // over here, `arguments` will be the "new" arguments when the final function is called!
                return thisFunction.apply(context, arguments);
            }
        );
    };

}(Function.prototype));