Created
November 6, 2020 12:05
-
-
Save yaakov123/4008b2e70ab8876e4a91a0ae6dbdbbcf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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