型链
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()
原文地址:https://www.jb51.cc/wenti/3280718.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。