JSHint's inspections now built into PhpStorm informed me about JavaScript magic numbers and I realise it'll make for clearer code to avoid using them.
I tried this:
var constants = {
millisecs: 1000,
secs: 60
};
and also this:
var constants = function () {
this.millisecs = 1000;
this.getMillisecs = function () {
return this.millisecs;
};
};
JsHint complains about both.
Taking the solution from this answer though works fine:
var constants = (function() {
var millisecs = 1000,
defaultMsgsPerSecond = 60;
this.getMillisecs = function() { return millisecs; };
this.getDefaultMsgsPerSecond = function() { return defaultMsgsPerSecond; };
})();
Presumably because of the closure. Why is it that this is accepted, whereas the other two suggestions taken from another SO question are not?
Edit: Although not triggering an error, it doesn't actually work. It errors to say constants is undefined. JsFiddle.
To clarify - by "works" I mean "doesn't trigger a warning from JsHint"