随笔分类 - JS 对象
摘要:原生JS(ES5)中的类 //原生JS中的类 //构造函数里面的方法和属性 function Person(name,age){ this.name=name; this.age=age; this.run=function(){ console.log(`${this.name} is ${thi
阅读全文
摘要:原生JS(es5)中的静态方法: //原生JS中的静态方法 function Person(name, age) { this.name = name; this.age = age; this.run = function () { console.log(`${this.name} is ${t
阅读全文
摘要:原生JS(ES5)中的继承 对象冒充继承: 没法继承原型链上面的属性和方法 function Person(name, age) { this.name = name; this.age = age; this.run = function () { console.log(`${this.name
阅读全文
摘要:单例模式: 多次实例化,只会执行构造函数一次,提高性能 在一个类只能有一个实例,即使多次实例化该类,也只返回第一次实例化后的实例对象 单例模式能减少不必要的内存开销,并且在减少全局的函数和变量冲突也具有重要的意义。 class Db { static getInstance() { //单例 if
阅读全文
摘要:构造函数是实例化的时候就会执行: class Db{ constructor(){ //构造函数,实例化的时候会调用 console.log('开始执行构造函数') this.connect() } connect(){ console.log("连接数据库") } find(){ console.
阅读全文

浙公网安备 33010602011771号