Skip to content

Instantly share code, notes, and snippets.

@xarimanx
Forked from branneman/call-apply-bind-proxy.js
Created September 29, 2015 06:33
Show Gist options
  • Save xarimanx/330ffe91844d08dd63a9 to your computer and use it in GitHub Desktop.
Save xarimanx/330ffe91844d08dd63a9 to your computer and use it in GitHub Desktop.

Revisions

  1. @branneman branneman revised this gist Jul 11, 2014. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions call-apply-bind-proxy.js
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    var fn = function(arg1, arg2) {
    var str = '<p>aap ' + this.noot + ' ' + arg1 + ' ' + arg2 + '</p>';
    document.body.innerHTML += str;
    },
    context = {
    'noot': 'noot'
    },
    args = ['mies', 'wim'];
    var str = '<p>aap ' + this.noot + ' ' + arg1 + ' ' + arg2 + '</p>';
    document.body.innerHTML += str;
    };
    var context = {
    'noot': 'noot'
    };
    var args = ['mies', 'wim'];

    // Calls a function with a given 'this' value and arguments provided individually.
    // Support: everywhere
  2. @branneman branneman renamed this gist Aug 2, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @branneman branneman revised this gist Aug 2, 2013. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions call-apply-bind.js
    Original file line number Diff line number Diff line change
    @@ -20,5 +20,10 @@ fn.apply(context, args);
    // provided value, with a given sequence of arguments preceding any provided
    // when the new function was called.
    // Support: ECMAScript >= 5 (thus >= IE9)
    boundFn = fn.bind(context, args[0], args[1]);
    boundFn();
    var boundFn1 = fn.bind(context, args[0], args[1]);
    boundFn1();

    // Same as bind()
    // Support: same as your jQuery version, available since 1.4
    var boundFn2 = $.proxy(fn, context, args[0], args[1]);
    boundFn2();
  4. @branneman branneman created this gist Jun 19, 2013.
    24 changes: 24 additions & 0 deletions call-apply-bind.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    var fn = function(arg1, arg2) {
    var str = '<p>aap ' + this.noot + ' ' + arg1 + ' ' + arg2 + '</p>';
    document.body.innerHTML += str;
    },
    context = {
    'noot': 'noot'
    },
    args = ['mies', 'wim'];

    // Calls a function with a given 'this' value and arguments provided individually.
    // Support: everywhere
    fn.call(context, args[0], args[1]);

    // Calls a function with a given 'this' value and arguments provided as an array
    // (or an array like object).
    // Support: everywhere
    fn.apply(context, args);

    // Creates a new function that, when called, has its 'this' keyword set to the
    // provided value, with a given sequence of arguments preceding any provided
    // when the new function was called.
    // Support: ECMAScript >= 5 (thus >= IE9)
    boundFn = fn.bind(context, args[0], args[1]);
    boundFn();