关于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
相关问答:
我也来一个趣味javascript:
打开以下html文件,依次按下G,L,C三个键,就会有奇迹出现!!
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" ......
最近 使用 js, 经常不能上网, 希望哪位达人 能提供一个
比较完整的 js离线文档,新一点儿,完整点儿的比较好,比如涉及 dom 这些
请指点一二.
万分感谢啊.
http://download.csdn.net/source/566130
......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml&q ......
请教各位大侠。
我有一页面a1.asp 需要打印。横向,上30,左5,右5,下5,页眉、页脚为空。
当用户到达a1.asp页面就自动设置上述描述。离开a1.asp就恢复默认设置。
请教大侠们如何编码。谢谢
没看明白,说得更明 ......
我想问一下如何在火狐中关闭,非脚本打开的页面,好像window.close()不管用O(∩_∩)O~,
百度一下,自己试试
<script language="javascript" type="text/javascript">
& ......