Skip to content

Instantly share code, notes, and snippets.

@gtkatakura
Last active July 2, 2016 02:29
Show Gist options
  • Save gtkatakura/282348f2ef615dcc9c4d63e3b46b268d to your computer and use it in GitHub Desktop.
Save gtkatakura/282348f2ef615dcc9c4d63e3b46b268d to your computer and use it in GitHub Desktop.
const hackerPowers = {
hackFacebook(userName) {
// something code
return `Olá, Mr ${userName}, meu nome é ${this.name}... e eu fodi a sua timeline ;)`;
},
};
const composeWithDelegation = (obj, delegator) => {
for (let [key, value] of Object.entries(delegator)) {
if (typeof value === 'function') {
obj[key] = (...args) => delegator[key].apply(obj, args);
}
}
return obj;
};
const user = composeWithDelegation({
name: 'Hackerman', // https://www.youtube.com/watch?v=V4MF2s6MLxY
sex: 'male',
}, hackerPowers);
const program = composeWithDelegation({
name: 'Zilean Computer',
codeObjectPath: 'C:\\Temp',
}, hackerPowers);
console.log(user.hackFacebook('Gabriel Takashi Katakura'));
console.log(program.hackFacebook('Antônio Vieira'));
hackerPowers.hackFacebook = () => 'Meu algoritmo está mais sofisticado, aproveitei a sua senha do facebook e já hackei todos as suas outras redes sociais. Onde está o seu deus agora?';
console.log(user.hackFacebook(''))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment