I was hoping somebody could help clarify the hasOwnProperty() method with relation to Event Objects.
I am trying to clone a mouse event (eventually this object will be passed to an iframe) I have already built a 'clone' function - but whenever i attempt to clone a window event (ie scroll, click etc) all instances of 'hasOwnProperty()' return false. For example, i iterate over the object - using hasOwnProperty() to check - and each property is returning false. This works for standard objects - but not event objects.
Is this because all of the properties within the event objects are inherited? Or is there an issue with the code?
Any enlightenment would be appreciated :)
Code snippet:
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);
Your assumption is correct - the e
argument is a hollow new MouseEvent
object that has no own properties, only those inherited from the prototype chain MouseEvent<-UIEvent<-Event
. Here's the inheritance diagram:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With