Base.js

Speedy function that checks equality of objects (doing some nasty type assumption)

License:
Public domain (http://unlicense.org).
Authors:
Yaroslaff Fedin
  1. 19
  2. 20
  3. 21
  4. 22
  5. 23
  6. 24
  7. 25
  8. 26
  9. 27
  10. 28
  11. 29
  12. 30
  13. 31
  14. 32
  15. 33
  16. 34
  17. 35
  18. 36
  19. 37
Object.equals = function(one, another) { if (one == another) return true; if ((!one) ^ (!another)) return false; if (typeof one == 'undefined') return false; if ((one instanceof Array) || one.callee) { var j = one.length; if (j != another.length) return false; for (var i = 0; i < j; i++) if (!Object.equals(one[i], another[i])) return false; return true; } else if (one instanceof Color) { return (one.red == another.red) && (one.green == another.green) && (one.blue == another.blue) && (one.alpha == another.alpha) } else if (typeof one == 'object') { if (one.equals) return one.equals(another) for (var i in one) if (!Object.equals(one[i], another[i])) return false; return true; } return false; };