Nodejs Function Bind bind(obj)

Here you can find the source of bind(obj)

Method Source Code

////  w ww  .ja  v a  2  s.c o m
// Additions to the Function prototype
//

Function.prototype.bind = function(obj) {
    var f = this;
    return function () {
   return f.apply(obj, arguments);
    };
};

Related

  1. myBind(context, ...args)
    Function.prototype.myBind = function (context, ...args) {
      return (...callArgs) => {
        return this.apply(context, args.concat(callArgs));
      };
    };
    Array.prototype.quickSort = function(comparator) {
      if (arguments[1] === 10) {
        return this.sort(comparator);
      this.quickSort(comparator, 10);
    };
    console.log([1,2, 4, 3].quickSort());
    
  2. bind(obj)
    Function.prototype.bind = function(obj) {
        var method = this;
        return function() { return method.apply(obj, arguments); };
    
  3. 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)));
      };
    };
    
  4. 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);
        })();
    };
    
  5. bind(bind)
    Function.prototype.bind = function (bind) {
        var self = this;
        return function () {
            var args = Array.prototype.slice.call(arguments);
            return self.apply(bind || null, args);
        };
    };
    
  6. bindArg()
    Function.prototype.bindArg = function () {
        var args = arguments,
            that = this;
        return function () {
            that.apply(this, args);
        };
    };
    
  7. bind(a)
    Function.prototype.bind = function (a)
      if (arguments.length < 2 && typeof arguments[0] === 'undefined') return this;
      var b = this,
        c = Array.prototype.slice.call(arguments).slice(1);
      return function ()
        var d = c.concat(Array.prototype.slice.call(arguments));
        return b.apply(a, d)
    ...
    
  8. bind(scope)
    Function.prototype.bind = function(scope) {
      var _function = this;
      return function() {
        return _function.apply(scope, arguments);
    };
    String.prototype.trim = function () {
        return this.replace(/^\s*/, '').replace(/\s*$/, '');
    };
    ...