Is it possible to add a callback function to a native JavaScript method? For instance, when Array.prototype.push('d')
is called, can I trigger another function as well?
UPDATE:
function Dummy() {};
Dummy.prototype = Array.prototype;
var arrObj = new Dummy();
var domElement = 'itemsList';
arrObj = ['werew', 'werewr', '234324'];
(function(native) {
arrObj.push = function() {
native.apply(this, arguments);
arrObj.render(domElement);
};
})(arrObj.push);
arrObj.addItem = function(item) {
this.push(item); //Uncaught TypeError: this.push is not a function
this.render(domElement);
return this;
}