Skip to content

Instantly share code, notes, and snippets.

@yaakov123
Created November 6, 2020 12:05
Show Gist options
  • Save yaakov123/4008b2e70ab8876e4a91a0ae6dbdbbcf to your computer and use it in GitHub Desktop.
Save yaakov123/4008b2e70ab8876e4a91a0ae6dbdbbcf to your computer and use it in GitHub Desktop.
const items = ['apple', 'orange', 'banana'];
// Here we are storing a reference to the native Array push method
const nativePush = Array.prototype.push;
Array.prototype.push = function(item) {
console.log(`Array push intercepted. Pushing ${item} into [${this}]`);
// Push the item into the array
nativePush.call(this, item);
}
items.push('grape'); // Will log the above statement to the console
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment