I'm creating a chat UI with jQueryUI:
$.widget("ui.chatwindow", {
options: {
nickname: "obama";
},
setNickname: function(nick){
var self = this;
var id_pre = 'wchat_' + self.options.nickname;
$('#' + id_pre + '\\:name').text(self.options.nickname);
},
setStatus: function(status){
var self = this;
var id_pre = 'wchat_' + self.options.nickname;
switch(status){
case 1:
$('#' + id_pre + '\\:status').removeAttr('class');
$('#' + id_pre + '\\:status').addClass('chat-icon-online');
$('#' + id_pre + '\\:status').attr('title','Online');
break;
...
default:
break;
}
...
},
...
}
I always write this in every method to change element class or text content:
var self = this;
var id_pre = 'wchat_' + self.options.nickname;
Is this a good or efficient way to code?