Wednesday 22 November 2017

Javascript - Make same function have different inputs

So in Java, you can
do:



void F(int x, int y)
{
run(x, y);
}

void F(String a) {

say(a);
}



but
in Javascript you always have to
do:



function F(x, y) {

if (typeof x == "string") {
say(a);
} else {
run(x,
y)

}
}



I
want to do something like the Java functions in Javascript without checking every single
thing, anyway to do that?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...