I would like to hook into the Node constructor function. Is it possible to overwrite the public Node constructor with my own Node constructor?
Currently only testing in chrome/firefox
(function() {
var _Node = window.Node;
var Node = function() {
Event.trigger("nodeCreation", this, arguments); // pseudocode
_Node.apply(this, arguments);
}
window.Node = Node;
console.log(document.createElement("div") instanceof _Node); // true
console.log(document.createElement("div") instanceof Node); // false
}());
I’m perfectly aware how dangerous this can be if I get it wrong. I’m also aware that this is powerfully versatile if I can get it right.
Is there any other way to overwrite native DOM objects. Extending their prototype isn’t a useful as overwriting the constructor
Nope. You cannot redefine constructor either for DOM Node or for any other DOM object (you can however do that for JavaScript objects).
Also, it is absolutely useless to try and redefine DOM objects constructors, since they generally cannot be invoked directly (except for Image and a couple of others), thus the issue of arguments is irrelevant. Tracking the DOM changes can be done using Mutation Events.