工厂模式
js中面向对象的四种模式对应的内存图
js中面向对象的四种模式对应的内存图优点:
简化代码操作(封装)
缺点:
1.对象不能细分
2.公有属性和方法存放浪费内存
构造函数模式
js中面向对象的四种模式对应的内存图js中面向对象的四种模式对应的内存图优点:解决了对象细分问题
缺点:内存问题没有彻底解决
原型对象模式
js中面向对象的四种模式对应的内存图js中面向对象的四种模式对应的内存图

继承
子类的原型指向父类的实例
Poor.prototype=new Rich();
Poor.prototype.constructor=Poor;

js中面向对象的四种模式对应的内存图js中面向对象的四种模式对应的内存图
借用构造函数:(注意函数中的this值的指向)
Rich.call(this,name,age,gender);

相关文章:

  • 2021-06-23
  • 2022-12-23
  • 2021-10-02
  • 2021-04-15
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-15
  • 2022-01-06
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2021-12-04
相关资源
相似解决方案