Try the following:
(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.
In any case, it is better not to override the built-in types (unless you want to use it for bullying / stub for testing purposes).
source
share