Code coverage report for function/bind.js

Statements: 100% (9 / 9)      Branches: 100% (2 / 2)      Functions: 100% (5 / 5)      Lines: 100% (8 / 8)     

All files » function/ » bind.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 241   1 8                   1 4 4 4       1      
define(function(){
 
    function slice(arr, offset){
        return Array.prototype.slice.call(arr, offset || 0);
    }
 
    /**
     * Return a function that will execute in the given context, optionally adding any additional supplied parameters to the beginning of the arguments collection.
     * @param {Function} fn  Function.
     * @param {object} context   Execution context.
     * @param {rest} args    Arguments (0...n arguments).
     * @return {Function} Wrapped Function.
     */
    function bind(fn, context, args){
        var argsArr = slice(arguments, 2); //curried args
        return function(){
            return fn.apply(context, argsArr.concat(slice(arguments)));
        };
    }
 
    return bind;
});