Last active
May 13, 2019 15:21
-
-
Save elledienne/ec31fb6cd6330ed68a281eb3a00756b2 to your computer and use it in GitHub Desktop.
[INTERVIEW] Coding challenge to test context, inheritance, string interpolation and destructuring
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
// 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Links
CodeShare - JSFiddle