函数和原型链

型链

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()

相关文章

谷歌翻译不能用了怎么办?最近有很多用户发现谷歌浏览器翻译...
ios17有不少新功能,此次更新重点升级了电话和短信的功能,新...
什么是IP地址?IP地址有什么用? 很简单,IP是整个TCP/IP协议...
网上找到的动图下载到本地保存时格式却成了webp,想要发表情...
小米手机一开相机就死机怎么处理? 处理手机一开相机就死机的...
充电宝押金什么时候可以退?具体操作充电宝退押金的操作步骤...