Can you solve this without throwing an error? The answer is a one-liner. This is from a dead job posting, the answer was requested in the response. I thought it was a clever way to weed out respondents, but I can't seem to answer it without also getting an error.
The obvious solution:
f.moo(alert(f.foo));
But that throws TypeError: callback is undefined { message="callback is undefined", more...}
var f = (function(){
return {
foo : "bar",
moo : function(callback){
callback.call(this)
}
}
})();
//alert "bar" by foo
You have to pass f.moo a function. You're calling alert and passing the result of alert( which is nothing) instead.
f.moo(function() { alert(this.foo); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With