[thelist] [JS]Equality

Marcus Andersson marcan at home.se
Mon Oct 20 10:42:59 CDT 2003

Consider the following:
function AClass() {
   // declare an inner class
  function AClassMode(msg) {
    this.toString = function() {
      return msg;
  AClass.MODE_A = new AClassMode("Mode A");
  AClass.MODE_B = new AClassMode("Mode B");
  AClass.MODE_C = new AClassMode("Mode C");
  // methods of class A
What will happen in the interpreter when I do an equality check?
AClass.MODE_A = AClass.MODE_B;
Will it compare references or something else? Is it specified?
Will there be a big performance hit if I do like that instead of using
1,2,3 instead? Example:
  AClass.MODE_A = 1;
  AClass.MODE_B = 2;
  AClass.MODE_C = 3;
I think the first way of doing it gives me a nicer OO (which I like :)
so I'd like to use it if it doesn't give me bad performance. 
What do you think? Am I just introducing complexity doing like that?
BTW: This is used in a system with well over 100 JS classes and these
types of "enums" will be used in a lot of places.

More information about the thelist mailing list