I am looking at the source code of the Video Title Adder chrome extension. I am new to javascript and tried to figure out what was the purpose of declaring the following global variable YTTA
as an anonymous function:
var YTTA = function () {};
YTTA.URLREGEX = /(?:youtube\.com\/watch\?.*v=|youtu\.be\/|y2u\.be\/)([-_A-Za-z0-9]{11})/i;
YTTA.ATTR_ID = 'data-ytta-id';
[...]
$(document).ready(function () {
chrome.extension.sendMessage({name : 'getOptions'}, function (resp) {
YTTA.links = resp["textlinks"]*1;
YTTA.image = resp["imglinks"]*1;
Why not just declare YTTA
as YTTA = {};
? What is the purpose of the anonymous function in the declaration var YTTA = function () {};
.
I tried to google this but could not find a quick answer.