Skip to content

Instantly share code, notes, and snippets.

@jeffrydegrande
Created April 6, 2012 23:12
Show Gist options
  • Save jeffrydegrande/2323857 to your computer and use it in GitHub Desktop.
Save jeffrydegrande/2323857 to your computer and use it in GitHub Desktop.
(function() {
Thing = {};
Thing.findAll = function(callback) {
$.getJSON('/things', function(data) {
if (data!=null) {
callback(data);
}
});
}
window.Thing = Thing;
})();
function doSomethingWithThings(things) {
}
Thing.findAll(doSomethingWithThings);
@sobrinho
Copy link

sobrinho commented Apr 7, 2012

@jeffrydegrande any reason to encapsulate the Thing into an anonymous function?

Also, you haven't used var on line 2, so, line 11 is unnecessary :P

@jeffrydegrande
Copy link
Author

I put it in an anonymous function because I have plenty versions of this in which I added functionality afterwards which I did not wanted to be available globally. One version of this for example keeps requests arounds in a hash which I just keep private in that scope without having to come up with safe names to avoid collisions

The var really is missing ... hacked this up in 20 seconds ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment