Javascript hasOwnProperty always false on Event objects?
I was hoping someone could help clarify the hasOwnProperty () method in relation to event objects.
I am trying to clone a mouse event (this object will eventually be passed to the iframe) I have already created a "clone" function, but whenever I try to clone a window event (eg scroll, click, etc.), all instances' hasOwnProperty () return false. For example, I iterate over an object - using hasOwnProperty () to check - and each property returns false. This works for standard objects, but not for event objects.
Is it because all properties of event objects are inherited? Or is there a problem with the code?
Any enlightenment would be appreciated :)
Snippet of code:
function cloneObject (o_node) {
var newObject = {};
for (var child_node in o_node) {
if (o_node.hasOwnProperty(child_node)) {
//no object properties are returning true at this point.
newObject[child_node] = o_node[child_node];
}else{
console.log("!hasOwnProperty()");
}
}
return newNode;
}
function onclick(e){
var cloned_object_e = cloneObject(e); //returns an empty object;
}
window.addEventListener('click', onclick);
+3
source to share
2 answers