<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD> <BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
function Rect(config){
this.width = config.width;
this.height = config.height;
this.area = function(){
alert(11);
};
} function myRect(config){
Rect.call(this,config);
this.name = config.name;
this.area = function(){
//这里如何调用一下父类的area方法?
alert(22);
//最终效果,是先alert(11),然后alert(22);
}
} var a =new myRect({width:1,heigth:2,name:3});
a.area();
//-->
</SCRIPT>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD> <BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
function Rect(config){
this.width = config.width;
this.height = config.height;
this.area = function(){
alert(11);
};
} function myRect(config){
Rect.call(this,config);
this.name = config.name;
this.area = function(){
//这里如何调用一下父类的area方法?
alert(22);
//最终效果,是先alert(11),然后alert(22);
}
} var a =new myRect({width:1,heigth:2,name:3});
a.area();
//-->
</SCRIPT>
</BODY>
</HTML>
解决方案 »
- 急,梅花雪树1.0的使用问题
- js正则取字符串,高手回答,谢谢!!!
- 为什么不要自动切换"content+i"的内容
- ------------ JS如何判断页面 DOCTYPE ------------
- 请问怎样用js代码来屏蔽多个radio单选框?
- 网页媒体播放器用Javascript怎么写?
- 难题:怎样用window.open(...)来模拟showModaldialog的功能?即在不关闭用open打开的页下使用户单击页面无效。
- 如何将键盘、鼠标的复制功能封掉!!请各位高人指点一二!!!
- help
- 菜鸟十万火急求救各位高手!关于javascript对media player的全面控制!
- 用js实现点击一个链接,模拟按下"Esc"键行为
- 两道面试题
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD> <BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
function Rect(config){
this.width = config.width;
this.height = config.height;
this.area = function(){
alert(11);
};
} function myRect(config){
Rect.call(this,config);
this.name = config.name;
var a = this.area
this.area = function(){
//这里如何调用一下父类的area方法?
a();
alert(22);
//最终效果,是先alert(11),然后alert(22);
}
} var a =new myRect({width:1,heigth:2,name:3});
a.area();
//-->
</SCRIPT>
</BODY>
</HTML>
area 里面有this的话就杯具了
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD> <BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
function Rect(config){
this.width = config.width;
this.height = config.height;
this.area = function(){
alert(11);
};
} function myRect(config){
var r = new Rect(config); //你这里这样来调用Rect
this.name = config.name;
this.area = function(){
r.area(); //这里就可以调用父类的area方法了。
//这里如何调用一下父类的area方法?
alert(22);
//最终效果,是先alert(11),然后alert(22);
}
} var a =new myRect({width:1,heigth:2,name:3});
a.area();
//-->
</SCRIPT>
</BODY>
</HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD> <BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
function Rect(config){
this.width = config.width;
this.height = config.height;
this.area = function(){
alert(11);
};
} function myRect(config){
Rect.call(this,config);
this.name = config.name;
var a = this.area;
var that = this; //这里定义
this.area = function(){
//这里面就可以用that来调用相应的方法了。
//这里如何调用一下父类的area方法?
a();
alert(22);
//最终效果,是先alert(11),然后alert(22);
}
} var a =new myRect({width:1,heigth:2,name:3});
a.area();
//-->
</SCRIPT>
</BODY>
</HTML>
见代码:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD> <BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
function Rect(config){
this.width = config.width;
this.height = config.height;
this.area = function(){
alert(this.heigth);
};
} function myRect(config){
Rect.call(this,config);
this.name = config.name;
var a = this.area;
var that = this; //这里定义
this.area = function(){
//这里面就可以用that来调用相应的方法了。
//这里如何调用一下父类的area方法?
that.area();
alert(22);
//最终效果,是先alert(11),然后alert(22);
}
} var a =new myRect({width:1,heigth:2,name:3});
a.area();
//-->
</SCRIPT>
</BODY>
</HTML>
this.width = config.width;
this.height = config.height; }
Rect.prototype.area = function() {
alert(this.width+" , "+this.height);
} function myRect(config) { Rect.call(this, config);
this.name = config.name; this.area = function() {
Rect.prototype.area.call(this, config);
//这里如何调用一下父类的area方法?
alert(22);
//最终效果,是先alert(11),然后alert(22);
}
} var a = new myRect({ width: 1, height: 2, name: 3 });
a.area();
this.width = config.width;
this.height = config.height;
this.area = function(){
alert(11);
}
}
function myRect(config){
this.superClass = Rect;
this.superClass(config);
this.superArea =this.area;
this.name = config.name; this.area = function(){
this.superArea();
//这里如何调用一下父类的area方法?
alert(22);
//最终效果,是先alert(11),然后alert(22);
}
}var a =new myRect({width:1,heigth:2,name:3});
a.area();
this.superClass = Rect;
this.superClass(config);
function Rect(config){}
Rect.prototype.area = function(){
alert("我是父方法");
}
function myRect(config){
arguments.callee.prototype.constructor.prototype.area(); //子类里调用父方法area
arguments.callee.prototype.area();//子类里调用重载方法area
}
myRect.prototype = new Rect();
myRect.prototype.area = function(){
alert("我是重载方法");
}
var rectObj = new myRect();
rectObj.constructor.prototype.area();//子类实例调用父类方法area
rectObj.area();//子类实例调用子类方法area
不过楼上的写法“myRect.prototype = new Rect();” 比较诡异!
这是灰常标准的javascript原型链继承的写法~~
area 里面this都是指向子类