As far as I am concerned the two are the same but we can do it your way if you have a strong preference (and are going to contribute something to the code aside from syntactical nitpicks ;-)
@TheRenamedException It makes easier to distinguish variables and functions. And you can put all function declarations at the bottom, but you can't do that with function expressions.
@Nyuszika7H As long as the functionality is the same, I'm easy
I think part of the reason why is because in my own projects I often redefine the functions, by binding them to objects and the like, that could be why. But we can do it with declarations
function test() {
foo(); // ReferenceError: foo is not defined
bar(); // logs 'test2 to the console
var foo = function() {
console.log('test1');
};
function bar() {
console.log('test2');
}
foo(); // logs 'test1' to the console
}
Yesterday, I looked at your code… couldn't guess how you call ChatExtension.define, since I couldn't find it in your code… now I see: it's inside the init function.
@Nyuszika7H why? I am supporting only Chrome and Firefox, which have localStorage. But that's OK, I will just show an alert if there is no localStorage
localStorage.setItem('foo', 'bar');
localStorage.getItem('foo');
localStorage.removeItem('foo');
// OR
localStorage['foo'] = 'bar';
localStorage['foo'];
delete localStorage['foo'];
// OR if the item name is a valid identifier:
localStorage.foo = 'bar';
localStorage.foo;
delete localStorage.foo;
All three does the same thing. :)
Invalid example:
localStorage.123myItem = 'this is invalid';
localStorage.#12345 = 'this is also invalid';
Identifiers must start with a letter, a dollar sign ($) or an underscore (_). They can also contain numbers, but only from the second character. You can also use a limited subset of Unicode, e.g. á, é.
@Nyuszika7H I did not know about that; thanks! I may not use that as all I am trying to do is built upon what balpha and Marc Gavel have already done with chat
did you know that only one open tab/window polls for messages and the rest use localStorage?
@Nyuszika7H My company has javascripts that are many thousands of lines long. Finding the one extra comma fouling it all up is the bane of my existence ;-)
SE Chat status script now available via Subversion. Anyone who wants write access, just ask me for a username.
@Nyuszika7H give me a username and password and I will grant you access. You can email it to@ sechatstatus@josh.gitlin.name or post here
ok @Nyuszika7H I have to go to a meeting, it being a work day for me and all. EMail me the username and password you want and I'll set up access so you can commit to the code base