Javascript如何判断对象是否相等
生活随笔
收集整理的這篇文章主要介紹了
Javascript如何判断对象是否相等
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在做表單頁面的時候,想判斷2個js對象,是不是所有完全相同。
這里是stackoverflow上的解決辦法,在這里記錄一下。
原文地址: http://stackoverflow.com/questions/1068834/object-comparison-in-javascript
Object.prototype.equals = function(x) {var p;for(p in this) {if(typeof(x[p])=='undefined') {return false;}}for(p in this) {if (this[p]) {switch(typeof(this[p])) {case 'object':if (!this[p].equals(x[p])) { return false; } break;case 'function':if (typeof(x[p])=='undefined' ||(p != 'equals' && this[p].toString() != x[p].toString()))return false;break;default:if (this[p] != x[p]) { return false; }}} else {if (x[p])return false;}}for(p in x) {if(typeof(this[p])=='undefined') {return false;}}return true; }?
轉載于:https://www.cnblogs.com/dkwlxq/archive/2013/03/19/2968602.html
總結
以上是生活随笔為你收集整理的Javascript如何判断对象是否相等的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用VirtualBox SDK之初步编
- 下一篇: 谈谈技术文档的编写