Thanx! I got #1 to work, and pushed the changes, would u be able to let me know if this was what you had in mind, or did i overcomplicate it? I wrote a new function to accomplish this task, lines 167-201.
It looks fine :-)
Also, I can't figure out how to reuse functions when prototypes are invloved. example/ addItemTmpl(), i rewrote on lines 189 and 94 because wasnt sure how to call a prototype fn within a prototype fn, if that's possible?
You can write:
EtsyClient.prototype.addItemTmpl = function(listing) {
$.get('./templates/item.tmpl').then(function(myTemplateHTML) {
var myTemplatingFn = _.template(myTemplateHTML);
var resultingHTML = myTemplatingFn(listing);
$('.listings, .head, .foot').fadeOut();
$('.item').append(resultingHTML);
});
}
and invoke it by doing:
EtsyClient.prototype.getListingInfo = function(ListingId) {
var self = this;
...
return $.getJSON(URIs.join('')).then(function(data) {
self.addItemTmpl(data.results[0]);
});
}
EtsyClient.prototype.getAllListings = function(type) {
var self = this;
...
return $.getJSON(URIs.join('')).then(function(data) {
...
$('body').on('click', '.btnRight', function() {
...
self.addItemTmpl(data.results[i]);
});
$('body').on('click', '.btnLeft', function() {
...
self.addItemTmpl(data.results[i]);
});
});
...
}
You could repeat this for drawCard()
and addLogo()
, too.