Skip to content

Instantly share code, notes, and snippets.

@defims
Forked from atk/LICENSE.txt
Last active June 14, 2016 01:16
Show Gist options
  • Save defims/badb4b09eedb7fc32644d61db1a0f19f to your computer and use it in GitHub Desktop.
Save defims/badb4b09eedb7fc32644d61db1a0f19f 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 <[email protected]>
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" ],
"version": "0.1.0"
}
<!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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment