型链
new __ proto __ constructor
构造函数<=========>实例化对 --------------------->原型对象<===========>构造函数
constructor prototype
__ proto __ constructor __ proto __
原型对象-------------->Object 原型对象<=======>Object构造函数------------>Null
prototype
ES6继承
Class类继承
// 父类 Person class Person { constructor(uname, age) { //属性 this.uname = uname; this.age = age } //方法 say() { return `我是${this.uname},我年龄${this.age}岁` } } let arr = Person('刘德华',38) console.log(arr.say()) //子类Student class Student extends Person { constructor(uname, age) { // this.uname = uname; // this.age = age; super(uname, age) } } var s1 = new Student("小红", 18) console.log(s1.say())
递归
举例:
var n = 1; function fun() { if (n > 6) return; console.log("我喜欢翘臀") n++ fun() } fun()
面向对象
ES5实现
function Star(uname, height, weight) { this.uname = uname; this.height = height; this.weight = weight this.say = function () { console.log(`我是${this.uname},我身高${this.height}厘米,体重${this.weight}公斤`) } } var ldh = new Star("刘德华", 174, 64) ldh.say() var lyf = new Star("刘亦菲", 170, 80) lyf.say()