Last active
December 23, 2018 20:33
-
-
Save ioxua/014e9dd17dea75dbb7e3662bb6c5448e to your computer and use it in GitHub Desktop.
Dwemthy's Array ES6 -- medium post 4
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 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