原型对象
var Student = {
name: "孙笑川",
age: 33,
run:function () {
console.log(this.name + "run ...")
}
}
var sun = {
name: "sun"
}
//原型对象
sun.__proto__ = Student;
function Student(name){
this.name = name;
}
//给Student新增一个方法
Student.prototype.hello = function () {
alert("hello")
}
class 继承
classs
关键字在ES6引入
1、定义一个类
class Student{
constructor(name){
this.name = name;
}
hello(){
alert("hello")
}
}
var sun = new Student("sun");
sun.hello()
2、继承
class Student{
constructor(name){
this.name = name;
}
hello(){
alert("hello")
}
}
class highStudent extends Student{
constructor(name,score){
super(name);
this.score = score;
}
myScore(){
alert("100分!")
}
}
var sun = new highStudent("sun",100);
本质:查看对象原型
原型链
评论 (0)