This bit of code is from this answer.
I'm trying to understand how it works but I'm not getting it all.
What I think is happening is TEST_ERROR is a closure so ErrorValue can't be changed. One would reference a value like this: TEST_ERROR.SUCCESS. Please correct me if either of those statements are incorrect.
What I don't understand is what the return statement is doing. It's returning an object made up of different ErrorValues, but returning it to what? And what is it returning from? And when is it being called?
var TEST_ERROR = (function() {
function ErrorValue(value, friendly) {
this.value = value;
this.friendly = friendly;
}
ErrorValue.prototype = {
toString: function() { return this.friendly; },
valueOf: function() { return this.value; }
};
return {
'SUCCESS': new ErrorValue(0, 'Success'),
'FAIL': new ErrorValue(1, 'Fail'),
'ID_ERROR': new ErrorValue(2, 'ID error')
};
})();
Thanks!
Paul