Skip to content

Instantly share code, notes, and snippets.

@fnando
Created March 20, 2012 22:07
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 fnando/2141765 to your computer and use it in GitHub Desktop.
Save fnando/2141765 to your computer and use it in GitHub Desktop.
Method overloading
function overload(functions) {
return function() {
functions[arguments.length].apply(this, arguments);
}
}
function List() {
}
List.prototype.add = overload([
function(){ console.log("no args", [this, arguments])},
function(title){ console.log("1 arg", [this, arguments])},
function(title, priority){ console.log("2 args", [this, arguments]);}
]);
var list = new List();
list.add();
list.add("Do something");
list.add("Do something else", "high");
@fnando
Copy link
Author

fnando commented Mar 20, 2012

Yep. Não gosto também.

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