This question is coming from a javascript point of view, but it certainly could apply to other languages.
I have been running into this more and more lately, and was wondering if there was a best practice, or at least good design standard, for when how to build your methods.
The obvious options that I see are as follows, along with a trivial example for each
Multiple methods:
this.makeGetRequest = function(controller){...} this.makeSynchronousGetRequest = function(controller){...} this.makePostRequest = function(controller, data){...}One method, with more parameters:
//data would be an optional parameter // this.makeRequest("friends", "GET", true); // this.makeRequest("friends", "POST", false, newFriend); this.makeRequest = function(controller, type, isSynchronous, data){...}One method, with an options parameter:
this.makeRequest = function(controller, type, options); this.makeRequest("friends", "POST", {data:newFriend, isSync:false});
The HTTP requests example is just motivated the question, but this works for any public facing function with varying amounts of customization/variables.
All three are obviously just as functional. But what's good practice? Is there a standard, or guideline that tends to be followed?