<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
</body>
</html>
<script>
function Person(name,age){
this.name = name;
this.age = age;
}
Person.prototype.hi = function(){
console.log("我的名字是"+this.name+",今年"+this.age);
}
Person.prototype.legs = 2;
Person.prototype.arms = 2;
Person.prototype.wall = function(){
return this.name+",会走路"
}
function Status(name,age,className){
Person.call(this,name,age);
this.className = className
}
Status.prototype = Object.create(Person.prototype);
Status.constructor = Status;
Status.prototype.hi = function(){
console.log("我的名字是"+this.name+",今年"+this.age+',班级是'+this.className);
}
Status.prototype.learn = function(subject){
console.log("我的名字是"+this.name+",今年"+this.age+',班级是'+this.className+"学科是"+subject);
}
var obj = new Status('tom',22,"一班");
console.log(obj.__proto__);
console.log(Status.prototype);
console.log(Status.prototype === obj.__proto__);//true
console.log(Status.prototype.__proto__);
console.log(Person.prototype);
console.log(Person.prototype === Status.prototype.__proto__);//true
console.log(Person.prototype.__proto__);
console.log(Object.prototype);
console.log(Person.prototype.__proto__ === Object.prototype);//true
console.log(Object.prototype.__proto__);
</script>
JavaScript深入浅出——函数面向对象
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 考虑真实世界中可能遇到的问题 狗门 2.0 运行一阵后又出现了问题,不只是主人自己的狗狗,其他任何狗叫唤,狗门都会...
- 快速实现一个狗门系统 这是一个关于狗门新项目。用户想要一个能用遥控器控制的狗门:按一下开门,再按一下关门。 程序员...