Skip to content

Instantly share code, notes, and snippets.

Created November 7, 2020 22:35
  • 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
What would you like to do?
// Store a reference to the native appendChild function
const nativeAppend = Node.prototype.appendChild;
// Override the appendChild method
Node.prototype.appendChild = function(node) {
// If the node is a "robber" don't append it
if ( === 'robber') {
console.log('denying robber entry to the bank');
console.log('letting person into the bank');
// use the native append function to add
// the node to the DOM
return, node);
// Get the "bank" from the DOM
const bank = document.body.querySelector('#bank');
const accountOwner = document.createElement('div'); = 'owner';
// Let the "account owner" into the bank (append it to the DOM)
bank.appendChild(accountOwner); // logs "letting person into the bank" to console
const robber = document.createElement('div'); = 'robber';
// Prevent the "robber" from accessing the bank (don't append to DOM)
bank.appendChild(robber); // logs "denying robber entry to the bank" to console
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment