Skip to content

Instantly share code, notes, and snippets.

// 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 (node.id === 'robber') {
console.log('denying robber entry to the bank');
return;
}
// Select the node that will be observed for mutations
const bank = document.getElementById('bank');
// Options for the observer (which mutations to observe)
const config = { childList: true };
// Callback function to execute when mutations are observed
const callback = function(mutationsList, observer) {
// Loop through all mutations
mutationsList.forEach(mutation => {
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);
}
const items = ['apple', 'orange', 'banana'];
Array.prototype.push = function(item) {
console.log(`Array push intercepted. Pushing ${item} into [${this}]`);
}
items.push('grape'); // Will log the above statement to the console
class Director {
constructor(builder) {
this.builder = builder;
}
constructFamilyHouse() {
return this.builder
.buildWalls(4)
.buildRoof('sloped')
.buildGarden(['trees', 'grass', 'peacocks'])
class House {
constructor() {
this.walls = null;
this.roof = null;
this.pool = null;
this.garden = null;
this.internet = null;
}
setWalls(walls) {
class DressClothesFactory {
constructor() {
}
getShoes() {
return new DressShoes();
}
getShirt() {
<?php
$adapter = Storage::getAdapter();
$client = $adapter->getClient();
$bucket = $adapter->getBucket();
$cmd = $client->getCommand('PutObject', [
'Bucket' => $bucket,
'Key' => 'ItWorks'
]);