Skip to content

Instantly share code, notes, and snippets.

@naholyr
Created May 25, 2011 13:06
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 naholyr/990936 to your computer and use it in GitHub Desktop.
Save naholyr/990936 to your computer and use it in GitHub Desktop.
Object destructuring for function parameters
function ajax(options) {
options = Object.extend({
"method": "POST",
"error": function() {},
"success": function() {},
// ...
}, options || {})
try {
return options.success(net(options.url, options.method))
} catch (err) {
return options.error(err)
}
}
function ajax({
"url": url,
"method": method = "POST",
"error": error = function() {},
"success": success = function() {}
}) {
try {
return success(net(url, method))
} catch (err) {
return error(err)
}
}
ajax({ "url": urlToService, "method": "GET" })
@bricecarpentier
Copy link

function ajax(options) {
    options = options || {};
    var url = options.url;
    var method = options.method || 'POST';
    var error = options.error || function() {};
    var success = options.success || function() {};

    try {
        return success(net(url, method));
    } catch (err) {
        return error(err);
    }
}

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