调用的实例分析及其在Javascript中的应用
使用调用和应用以及调用来实现js类的继承*
*矩形
* /
函数矩形(长,宽){
this.len = Len;
this.width =宽度;
}
*
××
* /
函数相乘(a,b){
返回一个B;
}
矩形
var矩形=新矩形(15, 30);
矩形区域
VaR比例= multiply.call(矩形、rectangle.len,长方形,宽度);
等于调用
/ /无功比例= multiply.apply(矩形,{ rectangle.len,长方形,宽度});
Document.write (the area of the rectangle is: +proportion);
document.write();
document.write( / ***********************线******************************** / );
实现。
功能的人(名字){
this.name =名称;
this.sayhello =函数(){
回到你好,+ this.name;
}
}
函数学生(姓名,性别,学校){
persion.call(这名字);
this.sex =性;
this.school =学校;
this.mysex =函数(){
返回this.sex;
}
this.myschool =函数(){
返回this.school;
}
}
VaR斯图=新学生('fengjx ','男','广西机电职业技术学院')
document.write(斯图打招呼:+ stu.sayhello());
document.write();
document.write(研究性:+ stu.mysex());
document.write();
document.write(斯图学校是:+ stu.myschool());
document.write();
演示:
以上是本文的全部内容,希望大家能喜欢。