This bit of code is in this answer .
I am trying to understand how this works, but I am not getting it all.
I think this TEST_ERROR is a close, so ErrorValue cannot be changed. One could refer to such a value: TEST_ERROR.SUCCESS. Please correct me if any of these statements is incorrect.
I do not understand what the return statement does. It returns an object consisting of different ErrorValues, but returns it to what? And what is he coming back from? And when is it 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!
Floor
source share