Someone asked me a trick question and I'm not sure how to do it. I'll appreciate any help.
Question: When you call Array.push()
, it should push as normal and should also make a call to custom function.
Here is my attempt:
Array.prototype.push = function() {
Array.prototype.push.call(this, arguments);
if(typeof customMethod === 'function') {
customMethod();
}
}
function customMethod() {
console.log('customMethod called');
}
But this doesn't work.