Skip to content

Instantly share code, notes, and snippets.

@ioxua
Last active December 23, 2018 20:33
Show Gist options
  • Save ioxua/014e9dd17dea75dbb7e3662bb6c5448e to your computer and use it in GitHub Desktop.
Save ioxua/014e9dd17dea75dbb7e3662bb6c5448e to your computer and use it in GitHub Desktop.
Dwemthy's Array ES6 -- medium post 4
const dwemthysArrayOf = (...creatures) => {
return new Proxy(creatures, {
get: function(target, prop, _) {
if (target.length == 0) {
console.log("[Whoa. You decimated Dwemthy's Array!]"); return;
}
let enemy = target[0];
if (enemy.life <= 0) {
target.shift();
enemy = target[0];
console.log(`[Get ready. ${enemy.name} has emerged.]`)
}
if (typeof enemy[prop] === "function")
return enemy[prop].bind(enemy)
return enemy[prop];
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment