So if I have some javascript like:
Foo.init = function(options) {
Bar.set_listener('some_event', function() {
console.log(options);
});
};
where I call Foo.init with some options like Foo.init({whatever: 'hi'}) and that Bar.set_listener method takes the callback and stores it, and then invokes it at some later time when 'some_event' is triggered....
will console.log print undefined or {whatever: 'hi'} ? The answer seems to be {whatever: 'hi'} but that confuses me. How does this callback when invoked have any idea how to reference the options variable passed in to Foo.init?
{whatever: 'hi'}. How, that's an implementation detail.