Skip to content

Instantly share code, notes, and snippets.

@yaakov123
Created November 6, 2020 12:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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