Created
November 16, 2012 14:27
-
-
Save tmr232/4087726 to your computer and use it in GitHub Desktop.
Javascript function binding crap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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