I am trying to create a basic javascript framework that you can pass different things into, including functions for it to execute later. Right now, I'm in a more simple testing phase, but I can't quite get the function calling to work. A piece of my code is here:
[My JS Fiddle][1]http://jsfiddle.net/mp243wm6/
My code has an object that holds different data, and I want to call the method later, but with data that is available at the time of creation. Here is a code snippet of the function that uses the function that is passed to the object:
clickMe : function() {
this.obj.click(function() {
this.func();
});
}
Any suggestions or things I should read are welcome.
thisis not what you think it is. It is not about the function itself, it is about how the function gets called.this.thisis determined by how the function is called, not by how it is declared. Here, the value ofthisin your callback will determined by the.click()function and will likely not be what you want. You can use.bind()on your anonymous function that you pass if you want to controlthisyourself.thisworks.