Last active
August 29, 2015 14:02
-
-
Save djfarrelly/e7c95ee2762d157d9bcf to your computer and use it in GitHub Desktop.
shorten function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==================== Existing ========================================= | |
shorten: function(url, callback, reshortenLink) { | |
// ... | |
}, | |
// called | |
Shortener.shorten('site.com/some/url', function(){ | |
// more logic | |
}, true) | |
// ==================== Alertnate ========================================= | |
// Potentially currying the functions so the last arg is always the callback | |
// reshortenLink is an optional param | |
shorten: function(url, reshortenLink, callback) { | |
if (typeof reshortenLink === 'function'){ | |
callback = reshortenLink; | |
reshortenLink = null; | |
} | |
// ... | |
}, | |
// called | |
Shortener.shorten('site.com/some/url', function(){ | |
// more logic | |
}) | |
// or | |
Shortener.shorten('site.com/some/url', true, function(){ | |
// more logic | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment