<p>a paragraph</p>
<div>a div with <span>a span</span> inside</div>
JavaScript
$.equals = function( a, b, options ) {
options = $.extend({
// if true, in case of inequality, a trace of the first difference is logged to the console
verbose: false,
// use 'strict' for ===, 'abstract' for ==
comparison: 'strict',
// if true, an item is compared, otherwise it is ignored
// receives a value and a key, returns true or false
filter: function () {
return true;
}
}, options || {});
var initial_step = false;
if (typeof options.trace == 'undefined') {
initial_step = true;
options.trace = [];
}
if (options.comparison == 'strict' ? a === b : a == b) {
return true;
}
var a_type = $.type(a);
var b_type = $.type(b);
if (! (a_type == b_type)) {
log(['types', a_type, b_type, a, b]);
return false;
}
var a_keys = decompose(a, options.filter).keys;
var b_keys = decompose(b, options.filter).keys;
var a_length = a_keys.length;
var b_length = b_keys.length;
if (! (a_length == b_length)) {
log(['lengths', a_length, b_length, a, b]);
return false;
}
var length = a_length; // == b_length
if (length == 0) { // a and b are scalars
return a === b;
}
// compare corresponding elements
for (var i = 0; i < length; i++) {
var key = a_keys[i];
var a_value = a[key];
var b_value = b[key];
var equal = $.equals( a_value, b_value, options );
if (! equal) {
log(['values at key "' + key + '"', a_value, b_value, a, b]);
return false;
}
}
if (initial_step) {
log(['values', null, null, a, b]);
}
return true;
//---
// returns true if the given object is a scalar (not in JavaScript terms, though...)
function isScalarValue(object) {
return object === null || /undefined|boolean|number|string/.test(typeof object);
}
// returns a...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.