Created
May 25, 2011 13:06
-
-
Save naholyr/990936 to your computer and use it in GitHub Desktop.
Object destructuring for function parameters
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
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) | |
} | |
} |
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
function ajax({ | |
"url": url, | |
"method": method = "POST", | |
"error": error = function() {}, | |
"success": success = function() {} | |
}) { | |
try { | |
return success(net(url, method)) | |
} catch (err) { | |
return error(err) | |
} | |
} |
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
ajax({ "url": urlToService, "method": "GET" }) |
bricecarpentier
commented
May 25, 2011
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment