Skip to content

Instantly share code, notes, and snippets.

@walterheck
Created May 4, 2014 18:51
Show Gist options
  • Save walterheck/534b296090323c9d79e6 to your computer and use it in GitHub Desktop.
Save walterheck/534b296090323c9d79e6 to your computer and use it in GitHub Desktop.
var getNodesAll = function(a, b, c, d) {
url = getURI(a, b, c, d);
rest.get(url + 'nodes').on('complete', function(result) {
if (result instanceof Error) {
console.log('Error:', result.message);
} else {
console.log(result);
}
});
}
@rajkissu
Copy link

rajkissu commented May 4, 2014

This would be the correct way to do this

// function definition
function getNodesAll(a, b, c, d, callback) {
  url = getURI(a, b, c, d);

  rest.get(url + 'nodes').on('complete', function(result) {
    if (result instanceof Error) {
      callback(result);
      return;
    }

    // assumed to be correct
    callback(null, result);
  });
}

// function invocation
getNodesAll('val-a', 'val-b', 'val-c', 'val-d', function (err, result) {
  if (err) {
    // do something about the error?
    throw err;
  }

  console.log('Results', result);
});

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