Last active
January 25, 2021 10:43
-
-
Save sielay/7050a677aee8d3301675fc0af52967e2 to your computer and use it in GitHub Desktop.
Most JS senior candidates didn't know why this won't work
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
function foo() { | |
setTimeout(function(){ | |
this.magic(); | |
}, 1); | |
} | |
foo.prototype.magic = () => console.log('magic'); | |
new foo(); | |
// it won't work. if you know why and look for VanillaJS/Angular position in London (Wimbledon) then send me your CV on ... (I don't work there anymore) |
Yes, you've spotted it. That was a honeypot question for candidates.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this
haven't got amagic
method inside thesetTimeout
function since it's an other context.This should work though: