Having some issues with scope and different browsers.
Here is an example of the issue I am having:
- var MyClass = function(property){
- this.property = property;
- }
- MyClass.prototype.request = function(){
- $.get('some_file.json', this.receiveJSON, 'json');
- }
- MyClass.prototype.receive = function(){
- alert(this instanceof MyClass); //false
- this.property = data.some_value;
- }
So because this in the handler is not an instance of MyClass I can't set the property instance variable.
I have also tried this:
- $.get('some_file.json', this.receiveJSON.bind(this), 'json');
And that works, but only in Google Chrome and Firefox 4 beta. IE, Opera nor Safari like the binding. Is there a way around this?
Thanks,
lang14