Binding Interview Question

by lsiv568

JavaScript

Function.prototype.lwsBind = function(scope) {
    var fn = scope || this;
    var boundArgs = Array.prototype.slice.call(arguments, 1);
    return function() {
        fn.apply(scope, boundArgs);
    }
}


function test(a, b) {
    console.log(a);
    console.log(b);
}

var boundFunc = test.lwsBind(null, 1, 3)();