<!doctype html>
<html>
<head>
<title>标题</title>
<meta charset="utf-8">
<script>
//inherits继承
//extends扩展
var father={
bal:100000000,
car:"infiniti",
intrSelf:function(){
console.log(
"I'm "+this.name+
",my bal is "+this.bal+
",my car is "+this.car
);
}
}
function Student(name,age){
this.name=name;
this.age=age;
}
//让所有子对象都继承father
Student.prototype=father;
/*
Student.prototype.intrSelf=
function(){
console.log(
"I'm "+this.name+
",I'm "+this.age
);
}
*/
var lilei=
new Student("Li Lei",11);
var hmm=
new Student("Han Meimei",12);
lilei.intrSelf();
hmm.intrSelf();
//让hmm继承father
//hmm.__proto__=father;
//Object.setPrototypeOf(hmm,father);
//lilei.intrSelf();
//hmm.intrSelf();
</script>
</head>
<body>
</body>
</html>
javascript面向对象(四)
最新推荐文章于 2022-08-09 15:00:06 发布