objEqual.js 637 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. function isEqual(x, y) {
  2. if (x === y) {
  3. return true
  4. }
  5. if (!(x instanceof Object) || !(y instanceof Object)) {
  6. return false
  7. }
  8. if (x.constructor !== y.constructor) {
  9. return false
  10. }
  11. for (var p in x) {
  12. if (x.hasOwnProperty(p)) {
  13. if (!y.hasOwnProperty(p)) {
  14. return false
  15. }
  16. if (x[p] === y[p]) {
  17. continue
  18. }
  19. if (typeof(x[p]) !== "object") {
  20. return false
  21. }
  22. if (!Object.equals(x[p], y[p])) {
  23. return false
  24. }
  25. }
  26. }
  27. for (p in y) {
  28. if (y.hasOwnProperty(p) && !x.hasOwnProperty(p)) {
  29. return false
  30. }
  31. }
  32. return true
  33. }
  34. module.exports = {
  35. isEqual
  36. }