Skip to main content
Code Review

Return to Question

deleted 2 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

jQuery Chat UI Widget Programming

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;

to change element class or text content. IsIs this a good or efficient way to code?

jQuery UI Widget Programming

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:

var self = this;
var id_pre = 'wchat_' + self.options.nickname;

to change element class or text content. Is this a good or efficient way to code?

jQuery Chat UI Widget

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?

deleted 142 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

JQuery jQuery UI Widget Programming


Hi, i'm creating chat ui with JQueryUI.
here some code:

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; 
 }
 ...
 },
 ...
}

My Question is iI always write this in every method:

var self = this;
var id_pre = 'wchat_' + self.options.nickname;

to change element class or text content
is. Is this a good or efficient way to code?
let me know the good and efficient way to do this.

thanks for your kind.

JQuery UI Widget Programming


Hi, i'm creating chat ui with JQueryUI.
here some code:
$.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; 
 }
 ...
 },
 ...
}

My Question is i always write in every method:

var self = this;
var id_pre = 'wchat_' + self.options.nickname;

to change element class or text content
is this a good or efficient way to code?
let me know the good and efficient way to do this.

thanks for your kind.

jQuery UI Widget Programming

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:

var self = this;
var id_pre = 'wchat_' + self.options.nickname;

to change element class or text content. Is this a good or efficient way to code?

Tweeted twitter.com/#!/StackCodeReview/status/79655296515059712
Source Link

JQuery UI Widget Programming


Hi, i'm creating chat ui with JQueryUI.
here some code:
$.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; 
 }
 ...
 },
 ...
}

My Question is i always write in every method:

var self = this;
var id_pre = 'wchat_' + self.options.nickname;

to change element class or text content
is this a good or efficient way to code?
let me know the good and efficient way to do this.

thanks for your kind.

default

AltStyle によって変換されたページ (->オリジナル) /