Skip to content

Instantly share code, notes, and snippets.

@matthiasak
Created October 9, 2014 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthiasak/789deeff022828893433 to your computer and use it in GitHub Desktop.
Save matthiasak/789deeff022828893433 to your computer and use it in GitHub Desktop.

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.

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