Scope of 'this' problem/understanding
I am incorrectly using 'this' and getting an error.
Todos.js:31TypeError: 'undefined' is not a function (evaluating 'this.setUser(user)')
My small project is to use sencha.io for user messages to improve my understanding and practices
. I am following the recent blog example of photo sharing by Nils Dehl.
From my init function on my controller i have a onlogin function were i want to store my user object.
The command
this.setUser(user) fails
/**
* When the controller is created it needs to
* listen for events generated by Ext.io.Controller.
*/
init: function() {
this.getApplication().sio.on({
authorized: this.onLogin,
usermessage: this.onUserMessage,
scope: this
});
},
/**
* When the application has an authentcated user.
*/
onLogin: function(user) {
console.log("onAuth", user,this)
this.setUser(user);
return true;
},
I have used console.log to inspect the instance of 'this' in my example and Nils.
His code has created the property of 'user' and in other cases he stores channel info as well.
I am puzzled to what I am misunderstanding and not achieving the same result.
While not yet familiar/proficient with sencha touch by expectation was that the use of 'this.setUser()' would create the 'parameter' user in the object 'this' for me to set and get.
Thanks in advance Maurice