Skip to content
Browse files

A better way to handle no args: check for function type

  • Loading branch information...
1 parent 3a76cf8 commit b4406303f4838de5a6f68e7a2c9dcbbd6c3e14b1 Will Fitzgerald committed
Showing with 12 additions and 4 deletions.
  1. +5 −1 lib/swagger.js
  2. +7 −3 src/swagger.coffee
View
6 lib/swagger.js
@@ -173,7 +173,11 @@
SwaggerOperation.prototype["do"] = function(args, callback, error) {
var body, headers;
if (args == null) args = {};
- if ((args != null) && !(callback != null)) callback = args;
+ if ((typeof args) === "function") {
+ error = callback;
+ callback = args;
+ args = {};
+ }
if (error == null) {
error = function(xhr, textStatus, error) {
return console.log(xhr, textStatus, error);
View
10 src/swagger.coffee
@@ -118,9 +118,13 @@ class SwaggerOperation
do: (args={}, callback, error) =>
- # if no callback, must be being called without parameters
- callback = args if (args? and !callback?)
-
+ # if the args is a function, then it must be a resource without
+ # parameters
+ if (typeof args) == "function"
+ error = callback
+ callback = args
+ args = {}
+
# Define a default error handler
unless error?
error = (xhr, textStatus, error) -> console.log xhr, textStatus, error

0 comments on commit b440630

Please sign in to comment.
Something went wrong with that request. Please try again.