js-js的不重载

时间:2022-04-23 09:26:29

* 什么是重载?方法名相同,参数列表不同
  - Java里面有重载
* js里面不存在重载!

<html>
<head>
<title>World</title>
<style type="text/css">
</style>
</head>
<body>
<script type="text/javascript"> function add(a, b) {
return a+b;
} function add(a, b, c) {
return a+b+c;
} function add(a, b, c, d) {
return a+b+c+d;
} alert(add(1,2)); //NaN
alert(add(1,2,3)); //NaN
alert(add(1,2,3,4));// </script>
</body>
</html>

  由此可以知道JS的不重载!