Skip to content

Instantly share code, notes, and snippets.

@atk
Forked from 140bytes/LICENSE.txt
Created June 22, 2011 10:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save atk/1039813 to your computer and use it in GitHub Desktop.
Save atk/1039813 to your computer and use it in GitHub Desktop.
Function.prototype.bind replacement (not fully functional yet)
Function.prototype.bind = (function(){}).bind ||
function(
a, // new context (new this)
b // placeholder for function (old this)
){
// store function
b = this;
// return new function
return function(){
// calling old function in new scope
b.apply(a,arguments)
}
}
Function.prototype.bind=(function(){}).bind||function(a,b){b=this;return function(){b.apply(a,arguments)}}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Alex Kloss <alexthkloss@web.de>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "funcbind",
"description": "Function.prototype.bind polyfill, not really ES5-compatible",
"keywords": [
"function",
"prototype",
"bind",
"polyfill"
]
}
<!DOCTYPE html>
<title>Foo</title>
<div>Expected value: <b>works</b></div>
<div>Actual value: <b id="ret"></b></div>
<script>
// write a small example that shows off the API for your example
// and tests it in one fell swoop.
var myFunction = Function.prototype.bind=(function(){}).bind||function(a,b){b=this;return function(){b.apply(a,arguments)}};
(function(){ document.getElementById( "ret" ).innerHTML = this; }).bind('works')();
</script>
@rwaldron
Copy link

I think it's possible to program responsibly and have fun ;D

Where is the damn "Like" button?

@atk
Copy link
Author

atk commented Aug 24, 2011

@rwldrn: on Facebook. We don't do this worshipping stuff here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment