5.面向对象编程
5.1 原型对象
JavaScript,java,c#。。。。
类:模板
对象:具体的实例
原型:
var user={
name:"cc",
age:3,
sex:'男',
run:function () {
console.log(this.name+"run...")
}
}
var xiaoming={
name:"xiaoming"
}
//小明的原型就是user
xiaoming.__proto__=user
class继承
class关键字是在ES6引入的
1.定义一个类,属性,方法
class student{
constructor(name) {
this.name = name;
}
hello(){
alert('hello')
}
}
2.继承
//定义一个学生类
class student{
constructor(name) {
this.name = name;
}
hello(){
alert('hello')
}
}
class xiaostudent extends student{
constructor(name,grade) {
super(name);
this.grade=grade;
}
myGrade(){
alert('我是小学生')
}
}
var xiaoming=new student("xiaoming")
var xiaohong=new xiaostudent("xiaohong",100)
原型链
__ proto__
标签:xiaoming,name,student,hello,JS,面向对象编程,var,class From: https://www.cnblogs.com/cyh822blogs/p/16667210.html