<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>每天一个JavaScript实例-apply和call的使用方法</title>
<script>
function Person(name,age){ //定义一个类,人类
this.name=name; //名字
this.age=age; //年龄
this.sayhello=function(){console.log("hello")};
}
function Print(){ //显示类的属性
this.funcName="Print";
this.show=function(){
var msg=[];
for(var key in this){
if(typeof(this[key])!="function"){
msg.push([key,":",this[key]].join(""));
}
}
console.log(msg.join("-----"));
};
}
function Student(name,age,grade,school){ //学生类
Person.apply(this,arguments);
Print.apply(this,arguments);
this.grade=grade; //年级
this.school=school; //学校
}
var p1=new Person("jake",10);
p1.sayhello();
var s1=new Student("tom",13,6,"清华小学");
s1.show();
s1.sayhello();
console.log(s1.funcName);
</script>
</head>
<body>
</body>
</html>
每天一个JavaScript实例-apply和call的使用方法
转载文章标签 html javascript java 文章分类 Java 后端开发
下一篇:Java面向对象编程(一)
-
typescript和javascript中如何使用bind方法?
本文给出typescript和javascript中如何使用bind方法的使用对比与建议。
函数绑定 全局对象 typescript javascript bind -
JavaScript中call()和apply()方法的区别
首先看一道面试题先不说该怎么解决这个问题,我们先学习下面的基础知识。首先明确this指的是谁以函数形式调用this指的是window对象构造函数形式调用this指的是调用它的对象…未完待续...
javascript es6 构造函数 window对象 数据 -
每天一个JavaScript实例-canvas绘图
每天一个JavaScript实例-canvas绘图画布
html javascript 2d -
每天一个JavaScript实例-动态省份选择城市
每天一个JavaScript实例-动态省份选择城市
html i++ javascript java -
每天一个JavaScript实例-推断图片是否载入完毕
每天一个JavaScript实例-推断图片是否载入完毕
html javascript java