Is it possible to override the Image
constructor in JS? So that, for example, every time a new Image()
is created, a message is written to the cons
Try this:
(function () {
var OriginalImage = window.Image;
window.Image = function (width, height) {
console.log('New image');
return new OriginalImage(width, height);
}
}());
Not sure if it will work in all browsers.
Anyway it is not best idea to override built in types (unless you want to use it to mock/stub for test purposes).