📄 8-15.txt
字号:
<script type="text/javascript">
<!--
Object.prototype.$super = function() {
var result;
try{
//首先获取基类的构造器,将它保存在变量result当中
result = eval(this.constructor).prototype.constructor;
//调用基类的构造器方法
result.apply(this,arguments);
}catch(err){
//如果不是内建类或者自定义类,或者不在构造器中调用该方法,那么就抛出错误
throw new Error("only can be used in constructor!");
}
return result;
}
function Person() {
if (arguments.length>2){
throw new Error("Two Arguments only can be allowd!");
}
this.name = arguments[0];
this.age = arguments[1];
}
Person.prototype.showInfo = function() {
return ("嗨!我的名字是"+this.name+",我现在"+this.age+"岁了。");
};
//=================================================
function Child(myName, myAge) {
this.$super(myName, myAge);//调用基类构造器
}
Child.prototype = new Person();
var child_1 = new Child("Jane", 8);
document.write(child_1.showInfo());
-->
</script>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -