Guest User

Untitled

a guest
Sep 26th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. // y and x can be whatever you look for equality
  2. function objeq(y,x)
  3. {
  4. var p;
  5. for(p in y) {
  6. if(typeof(x[p])=='undefined') {return false;}
  7. }
  8.  
  9. for(p in y) {
  10. if (y[p]) {
  11. switch(typeof(y[p])) {
  12. case 'object':
  13. if (!objeq(y[p],x[p])) { return false; } break;
  14. case 'function':
  15. if (typeof(x[p])=='undefined' ||
  16. (p != 'equals' && y[p].toString() != x[p].toString()))
  17. return false;
  18. break;
  19. default:
  20. if (y[p] != x[p]) { return false; }
  21. }
  22. } else {
  23. if (x[p])
  24. return false;
  25. }
  26. }
  27.  
  28. for(p in x) {
  29. if(typeof(y[p])=='undefined') {return false;}
  30. }
  31.  
  32. return true;
  33. }
Add Comment
Please, Sign In to add comment