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
// 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; | |
} |
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
// 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 => { |
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); | |
} |
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']; | |
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 |
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
class Director { | |
constructor(builder) { | |
this.builder = builder; | |
} | |
constructFamilyHouse() { | |
return this.builder | |
.buildWalls(4) | |
.buildRoof('sloped') | |
.buildGarden(['trees', 'grass', 'peacocks']) |
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
class House { | |
constructor() { | |
this.walls = null; | |
this.roof = null; | |
this.pool = null; | |
this.garden = null; | |
this.internet = null; | |
} | |
setWalls(walls) { |
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
class DressClothesFactory { | |
constructor() { | |
} | |
getShoes() { | |
return new DressShoes(); | |
} | |
getShirt() { |
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
<?php | |
$adapter = Storage::getAdapter(); | |
$client = $adapter->getClient(); | |
$bucket = $adapter->getBucket(); | |
$cmd = $client->getCommand('PutObject', [ | |
'Bucket' => $bucket, | |
'Key' => 'ItWorks' | |
]); |