I am trying to understand the behaviour of a jQuery plugin but I don't understand the way it is coded. I did my best to no avail. Could you please give me a link explaining this way of coding?
(function($) {
$.widget("ui.chatbox", {
....
_create: function() {
var self = this,
options = self.options,
title = options.title || "No Title",
uiChatbox = (self.uiChatbox = $('<div></div>'))
.appendTo(document.body)
}
....
}(jQuery));
PS: The whole code is a widget created by the jQuery UI Widget Factory. You can see the whole code here.
In the official documentation example, the _create content is separated by semicolon, what is usual (for me). Help is appreciated.
In javascript, when declaring new variables with the var keyword, you can separate each declaration by commas. Which allows you to only use the var keyword once. Its a sort of short-hand.
For example:
var self = this,
options = self.options,
title = options.title || "No Title",
uiChatbox = (self.uiChatbox = $('<div></div>')).appendTo(document.body)
Is the same as:
var self = this;
var options = self.options;
var title = options.title || "No Title";
var uiChatbox = (self.uiChatbox = $('<div></div>')).appendTo(document.body);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With