Javascript Puzzle - One Liner
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 us

Javascript Puzzle - One Liner
===

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 us
