I\'m trying to extend the Array.push method so that using push will trigger a callback method, then perform the normal array function.
I\'m not quite sure how to do
The question is old, but for those who'll find this question nowadays, there's another, more native method to achieve this: Proxy
const target = [];
const handler = {
set: function(array, index, value) {
// call callback function here
// The default behavior to store the value
array[index] = value;
// Indicate success
return true;
}
};
const proxyArray = new Proxy(target, handler);