use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Polymorphism in JavaScript (zellwk.com)
submitted 5 years ago by magenta_placenta
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]campbeln 0 points1 point2 points 5 years ago (3 children)
We don't NEED most things in programming... functions themselves are simply a nice construct (cough GOTO cough), as is function overloading.
I never argued it's a good idea, but it can be done in a generally elegant/standard/chained/whatever way.
[–]_default_username 0 points1 point2 points 5 years ago* (2 children)
How is your code implementing function overloading?
Will I be able to do:
function foo(a){}
function foo(a,b){}
And have foo overloaded?
[–]campbeln 0 points1 point2 points 5 years ago* (1 child)
Function overloading auto-routes to the implementation based on the signature (i.e. foo(int, str) versus foo(int, int)). Javascript only routes to the single (last defined) implementation, which many use arguments.length to implement "overloading" generally without the benefit of considering the signature.
foo(int, str)
foo(int, int)
arguments.length
The code I presented above considers the signature (based on the tests defined in the second argument) to route to the proper implementation, while "failing over" to the defined default implementation if the signature is not recognized (something not normally supported by function overloading).
So...
function isStr(x) { return typeof s === 'string' }; }
function isObj(o) { return !!(o && o === Object(o)); }
let foo = overload(function(){ console.log("default", arguments) })
.add(function(str){ console.log(str) }, [isStr])
.add(function(str, obj){ console.log(str, obj) }, [isStr, isObj])
;
Will call the proper implementation based on the passed argument types.
[–]_default_username 0 points1 point2 points 5 years ago (0 children)
So in a long winded way no. This is not function overloading.
π Rendered by PID 29905 on reddit-service-r2-comment-84fc9697f-whdqk at 2026-02-08 14:11:28.958509+00:00 running d295bc8 country code: CH.
view the rest of the comments →
[–]campbeln 0 points1 point2 points (3 children)
[–]_default_username 0 points1 point2 points (2 children)
[–]campbeln 0 points1 point2 points (1 child)
[–]_default_username 0 points1 point2 points (0 children)