Ok, that's clear to me now, i have to compare only object like that :
var o1={element
ne,
type:'keyup',code:82,action:setToRed,modifiers:{shift:false,alt:false}};
then with Strings, Numbers Simple Objects having boolean values, string
or number, Function (in this case "setToRed") and DOM Element (in this
case "one" is a DIV).
in that case you could compare each property in that list using ===
except, possibly, for the DOM element - see below.
because i need to compare objects having DOM Element as value of a
property and experimetally i've found the comparaison between to DOM
Elements is correct, surprisingly (ie
toto=document.getElementById('toto') is "===" to
anotherToto=document.getElementById('toto').
It's not all that surprising, since most browsers probably really do use
the same host object to refer to the same DIV. But as far as I know,
they're not *required* to do so, and even if they did, I'm not sure that
host objects are required to be === to themselves (though still, as far
as implementing them goes, it's probable that they are). If you're using
valid markup, and the DIVs you're comparing all have ID properties and
are in the same document, you could just compare the ID, since IDs
should be unique. IOW:
document.getElementById("bla").id == document.getElementById("bla").id
in the above ewample the way i do the "comparator" is (simplified) :
- compare with null both sides;
- if both objects have the property 'nodeName' I'll compare the object
identity like that : anObject===anotherObject
This might not be safe. See above.
- if not and it is an object, I'll compare all property/value pairs
recursively, like that :
if(!(this[p].eql(o[p]))){return false;}
As far as I can see from your types of properties, you can just do
if (this[p] !=== o[p]) return false;
(my "comparator" is a prototype of Object :
Object.prototype.eql=function(o){...}
the reason for this[p].eql(o[p])
replacing "this[p]===o[p]"
I don't think you need that.
then i needed to know the best way to say 'this object is of type DOM
Element'...
In this case, I'd just check if the object as an id property; if so,
compare that, otherwise do object1 === object2. If you can control your
environment enough, that should work. If you can't control your
environment, that may not, but in that case, there's probably no general
solution.