Overwrite HTMLNode

I would like to connect to 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 understand perfectly how dangerous it is if I am mistaken. I also know that this is very universal, if I can fix it.

Is there any other way to overwrite my own DOM objects. Extending your prototype is not useful for rewriting a constructor

+1
source share
1 answer

Nope. You cannot override the constructor for either the DOM Node or any other DOM object (however, you can do this for JavaScript objects).

In addition, it is completely useless to try and redefine the constructors of DOM objects, since they usually cannot be called directly (except for Image and a few others), so the question of arguments does not matter. Tracking DOM changes can be done using Mutation events.

+1
source

All Articles