Last active
December 20, 2015 04:28
-
-
Save suzuki0keiichi/6070724 to your computer and use it in GitHub Desktop.
Scala.jsでoverloadがどのように変換されるか
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 関数名のポストフィックスでパラメーター情報がつく | |
ScalaJS.c.helloworld\ufe33HelloWorld$.prototype.hello\ufe34T = (function() { | |
return "hello world!" | |
}); | |
ScalaJS.c.helloworld\ufe33HelloWorld$.prototype.hello\ufe34Ljava\ufe33lang\ufe33Integer\ufe34T = (function(arg$num) { | |
return ("hello world! " + arg$num) | |
}); | |
ScalaJS.c.helloworld\ufe33HelloWorld$.prototype.hello\ufe34T\ufe34T = (function(arg$text) { | |
return ("hello world! " + arg$text) | |
}); | |
// パラメーターの数、型で分岐される | |
ScalaJS.c.helloworld\ufe33HelloWorld$.prototype.hello = (function(arg$1) { | |
switch (arguments.length) { | |
case 0: | |
return this.hello\ufe34T(); | |
case 1: | |
if ((typeof(arg$1) === "string")) { | |
return this.hello\ufe34T\ufe34T(arg$1) | |
} else { | |
if (ScalaJS.is.java\ufe33lang\ufe33Integer(arg$1)) { | |
return this.hello\ufe34Ljava\ufe33lang\ufe33Integer\ufe34T(arg$1) | |
} else { | |
throw "No matching overload" | |
} | |
}; | |
default: | |
throw "No matching overload"; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 関数名のポストフィックスでパラメーター情報がつく(パラメーター名がスッキリした?) | |
ScalaJS.c.HelloWorld$.prototype.hello__T = (function() { | |
return "hello world!" | |
}); | |
ScalaJS.c.HelloWorld$.prototype.hello__Ljava_lang_Integer__T = (function(num) { | |
return ("hello world! " + num) | |
}); | |
ScalaJS.c.HelloWorld$.prototype.hello__T__T = (function(text) { | |
return ("hello world! " + text) | |
}); | |
// 前回調べた時と違ってswitchで分岐する外部呼び出し用関数がなくなっていたため、上記関数の1つを呼び出してみる | |
// 呼び出し時に解決させている模様(実行時パフォーマンス対策か) | |
ScalaJS.modules.HelloWorld().hello__Ljava_lang_Integer__T(ScalaJS.modules.scala_Predef().int2Integer__I__Ljava_lang_Integer(10)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object HelloWorld { | |
def hello = "hello world!" | |
def hello(num: Integer) = "hello world! " + num | |
def hello(text: String) = "hello world! " + text | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment