js中ES6的继承


<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
	</body>
</html>
<script>
	class Person{
		constructor(newId,newName) {
		    this.id = newId;
			this.name = newName;
		}
		eat(){
			console.log("eat()");
		}
	}
	//class 子类名 extends 父类名
	class Student extends Person{
		constructor(newId,newName,newScore){
			//super关键字等价于父类构造方法
			super(newId,newName);
			this.score = newScore;
		}
	}
	
	let s = new Student(1,"老王",99);
	
	console.log(s.id);
	s.eat();
</script>

你可能感兴趣的:(javascript)