I can explain the question at its best by code:
/**
* javascript version of java.util.Set
*/
Set: function(propertyKey) {
var s = {}, hasValidPropsKey;
propertyKey = propertyKey || 'id';
/**
* Adds individual element or object or Array or Set
* @param ele
*/
this.add = function(ele) {
var tat = this;
/**
* Adds an element to the set.
* @param element can be primitive, object, array or Set
*/
var addFunc = function(element) {
if(!element instanceof Object) {
s[element] = element; //yes its just json key value pair that we can leverage as set
} else {
s[element[propertyKey]] = element; //Key will alway be whatever initialized
}
};
if(ele instanceof Array) {
$.each(ele, function(i, val) {
addFunc(val);
});
} else if(ele instanceof 'Set'){//right here , how to do this
tat.add(ele.toArray());
} else {
addFunc(ele);
}
};
//some more code...
Now see this piece of code
if(ele instanceof 'Set'){//right here , how to do this
tat.add(ele.toArray());
}
How can I just refer the class/function or make a check that object is of same type?
Edit I got one way while drafting this question
if(ele.constructor.name === 'Set'){
tat.add(ele.toArray());
}