The Resources module
In terms of code, building a module that contains a model and building one that contains a resource is not so different. The module pattern applied is the same. Nevertheless, you don't need to create instances of the resources. To apply CRUD operations to the models, you just need an object that handles this responsibility. Therefore, the resources will be singletons, as done in the following steps:
Open the
resources/ProductResource.js
file.Create the top hierarchy module:
var Shop; Shop = Shop || {};
Create the
Resources
namespace:Shop.Resources = Shop.Resources || {};
Define
ProductResource
using the module pattern:Shop.Resources.ProductResource = (function(){ })()
Set the dependencies. In this case, jQuery is the dependency you need. jQuery is a global object and you don't need to pass it as a dependency, but it's a good practice to do so.
Shop.Resources.ProductResource = (function($){ }(jQuery);
Finally, set the following code in the
resources/ProductResource.js
file....