Posted By

Sephr on 04/13/09


Tagged

function bind


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

indamix
wirenaught


function.bind


 / Published in: JavaScript
 

function.bind Usage: function.bind(thisObject [, arg [... argN]])

Function.bind Usage: Function.bind(function, thisObject [, arg [... argN]])

Based off the Prototype JavaScript framework's function.bind but without Prototype dependancies.

Example:

function foo(a, b) {
    return [this, a, b].join(", ")
}
var bar = foo.bind(0, 1);
bar(2) == "0, 1, 2"
  1. Function.prototype.bind = function () {
  2. if (arguments.length < 2 && arguments[0] === undefined) {
  3. return this;
  4. }
  5. var thisObj = this,
  6. args = Array.prototype.slice.call(arguments),
  7. obj = args.shift();
  8. return function () {
  9. return thisObj.apply(obj, args.concat(Array.prototype.slice.call(arguments)));
  10. };
  11. };
  12.  
  13. Function.bind = function() {
  14. var args = Array.prototype.slice.call(arguments);
  15. return Function.prototype.bind.apply(args.shift(), args);
  16. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: jordansair002 on October 7, 2010

The Air Jordan shoes Michael Jackson Edition is inspired by the Cheap Jordans. There are multiple designs, which can be viewed our Nike jordan website. This has for being the a single issue the ultimate MJ admirer is lacking in research of the total outfit, unless they program on obtaining Air Yeezy to launch some specific edition socks Air Yeezy shoes too.

You need to login to post a comment.