当一个已经重载的函数被调用,已重载的函数的会调用相应的参数,依赖的是函数参数类型.如果参数类型匹配重载法则,重载就会被调用,如果参数类型不匹配任何重载法则,一个清除处理决定重载的调用.这个清出处理是基本就是怎样能容易将当去前的类型转换成能重载的类型!详细可以看Coercion in JScript.例如类的MethodOverload已经有三个重载方法名为Greetings, 首先overload 没有碍参数,第二有两个参数,第三个有三个参数.
var methodOverload =new MethodOverload(); methodOverload.Greetings(); methodOverload.Greetings("Mr. Brown"); methodOverload.Greetings(97, "Mr. Brown"); class MethodOverload }
输出的结果是:
Hello, and welcome! Hello, Mr.Brown! Hello, Mr.Brown! Your ticket number is 97.