Skip to content

Instantly share code, notes, and snippets.

@elledienne
Last active May 13, 2019 15:21
Show Gist options
  • Save elledienne/ec31fb6cd6330ed68a281eb3a00756b2 to your computer and use it in GitHub Desktop.
Save elledienne/ec31fb6cd6330ed68a281eb3a00756b2 to your computer and use it in GitHub Desktop.
[INTERVIEW] Coding challenge to test context, inheritance, string interpolation and destructuring
// Remember to overwite the code in CodeShare, JSFiddle, etc. to restore the inital state of the test and to avoid
// showing to candidates the changes made during other interwies
// TASKS:
// 1. Ask to developer to go through the file and analyze it. The dev should notice:
// - Constructor (at this point we can talk also about classes in ES6
// - Destructuring
// - String interpolation
// - Context (and should notice (and fix) that the callback passed to the onclick will log "I'm a button and I undefined" because it's not bound to
// the context ('dog')
function Animal({ type, sound, action }) {
this.type = type;
this.sound = sound;
this.action = function() {
console.log(`I'm a ${this.type} and I ${this.sound}`);
}
}
const dog = new Animal({
type: 'dog',
sound: 'bark'
})
dog.action();
const barkButton = document.createElement('input');
barkButton.type = 'button';
barkButton.value = 'Bark !';
barkButton.onclick = dog.action;
document.getElementsByTagName('body')[0].appendChild(barkButton);
@elledienne
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment