Skip to content

Instantly share code, notes, and snippets.

@tmr232
Created November 16, 2012 14:27
Show Gist options
  • Save tmr232/4087726 to your computer and use it in GitHub Desktop.
Save tmr232/4087726 to your computer and use it in GitHub Desktop.
Javascript function binding crap
// Define a class with a method
function MyClass(value) {
this.value = value;
this.function = function() {
return this.value;
};
}
// Instanciate the class
my_class = new MyClass("my value");
// Pass the method as a callback to the timer
window.setInterval(my_class.function, 1000);
// Sadly, we get an error 'cause window.value is undefined.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment