Asynchronous JavaScript - Callbacks vs Deferred/Promise [duplicate]
Possible Duplicate: What are the differences between Deferred, Promise and Future in Javascript? Lately I've been making an effort to improve the quality of my JavaScript applications. One pattern I've adopted is to use a separate "data context" object to load data for my application (previously I was doing this directly in my view models). The following example returns data that is initialized on the client: var mockData = (function($, undefined) { var fruit = [ "apple", "orange", "banana", "pear" ]; var getFruit = function() { return fruit; }; return { getFruit: getFruit } })(jQuery); In