关于javascript的重载 - Web 开发 / JavaScript
请问这样的话子类不是根据参数列表的不同重载了a方法吗??
但是为什么输出是Child Method count undefined 呢??
不是应该根据参数列表的不同调用了从父类继承的a方法,输出Parent Method count吗??
请指教!~~
function Parent() {
this.a=function(){
alert("Parent Method count");
}}
Children.prototype = new Parent();
function Children() {
this.a = function(cc) {
alert("Child Method count" + cc);
}
}
var c = new Children();
c.a();
JavaScript下没有重载,这样写是把Parent的函数覆盖了。
要重载需要自已做些处理```
因为你写的子类a()方法覆盖父类的a()方法,
只要注释掉子类a()方法就可以了。
this.a=function(){
alert("Parent Method count");
}}
Children.prototype = new Parent();
function Children() {
/*
this.a = function(cc) {
alert("Child Method count" + cc);
}
*/
}
var c = new Children();
c.a();
function Parent() {
this.a=function(){
alert("Parent Method");
}}
Children.prototype = new Parent();
function Children() {
this.b = funct
相关问答:
上联:Java和JavaScript
自己试试:
下联:面包和面包车
下联:SQL和MySQL
呵呵。
me and myself
下联:JavaScript和Java
兔子和兔子屎!
!
再来一个:C和C++
引用
下联:JavaScript和Jav ......
<html>
<head>
<title>look the status change</title>
</head>
<body>
<script type="text/javascript">
var nowtime ;
var year ;
var month ,da ......
<%
function getName(num)
......
end function
%>
<script>
var num=1;
var xx=<%=getName(num)%>
</script>
如何才能在java ......