Nodejs Function Bind myBind(context, ...args)

Here you can find the source of myBind(context, ...args)

Method Source Code

Function.prototype.myBind = function (context, ...args) {
  return (...callArgs) => {
    return this.apply(context, args.concat(callArgs));
  };/*from w  w w  . ja v a 2  s .  co  m*/
};

Array.prototype.quickSort = function(comparator) {
  if (arguments[1] === 10) {
    return this.sort(comparator);
  }

  this.quickSort(comparator, 10);
};

console.log([1,2, 4, 3].quickSort());

Related

  1. bind(obj)
    Function.prototype.bind = function(obj) {
        var method = this;
        return function() { return method.apply(obj, arguments); };
    
  2. bind()
    Function.prototype.bind = function(){
      var fn = this, args = Array.prototype.slice.call(arguments),
        object = args.shift();
      return function() {
        return fn.apply(object, args.concat(Array.prototype.slice.call(arguments)));
      };
    };
    
  3. bind(bind,args)
    Function.prototype.bind = function(bind,args){
      var self = this;
      var options = args;
      return function(){
        var args = (options != undefined) ? options.extend(arguments) : arguments;
        return (function(){
          return self.apply(bind || null, args);
        })();
    };
    
  4. bind(obj)
    Function.prototype.bind = function(obj) {
        var f = this;
        return function () {
      return f.apply(obj, arguments);
        };
    };