当前位置:网站首页>new做了哪几件事
new做了哪几件事
2022-06-12 20:29:00 【站在桥上烤冷面】
- 创建了一个空对象
- 让子对象自动继承构造函数的原型对象
- 调用构造函数,替换实参,将this替换为正在创建的新对象
- 将新对象的内存地址返回
优点: 重用对象结构代码
缺点: 如果构造函数中包含方法定义,则每次创建新对象都会重复创建相同方法的副本。——浪费内存!
解决:如果发现多个子对象都需要使用相同的功能时,就可以使用继承来解决
什么是继承?父对象中的成员,子对象无需重复创建就可以直接使用,就像使用自己的成员一样
JS中的继承都是通过原型对象来实现的
什么是原型对象?替所有子对象集中保存共有的属性和方法的特殊父对象
如何:创建原型对象:不用自己创建,而是在定义构造函数时,程序自动为我们生成。
找到原型对象?构造函数中都有一个自带属性prototype,指向自己匹配的原型对象即:构造函数.prototype
向原型对象中添加共有的属性和方法构造函数.prototype.共有方法 = function(){}
构造函数.prototype.共有属性=属性值
今后,用子对象.访问对象的成员时,js引擎先在子对象内部查找自有的属性。如果子对象没有,则js引擎会自动延_ _proto_ _属性去父元素查找。如果在父元素中找到了想要的属性或方法,则和访问子对象的方法一样调用。
边栏推荐
- Introduction to the characteristics of building a balancer decentralized exchange market capitalization robot
- Is foreign exchange speculation formal and is the fund safe?
- In 2022, FISCO bcos MVP recognized that the channel was open and invited you to become an open source leader
- How do indexes match?
- Wechat jsapi payment pit summary
- go --- 监控文件变化
- What does SQL replace or
- [games101] class note 8 - shading (shading frequency, graphics pipeline, texture mapping)
- The difference between MySQL full table scanning and indexing
- 部署static pod方式部署etcd集群
猜你喜欢

A simple understanding of consistent hash

House raiding 3

20 shortcut keys for vs code!

Installation of xv6 system

华尔街备忘单(Wall Street Cheat Sheet)

Niuke net: somme des trois nombres

Introduction to system mode development of rouya wechat mall
![[generation confrontation network learning III] reading notes of Bigan paper and its principle understanding](/img/6b/0f0815e20cdf6da28793562bcaede1.png)
[generation confrontation network learning III] reading notes of Bigan paper and its principle understanding
![[games101] class note 8 - shading (shading frequency, graphics pipeline, texture mapping)](/img/90/f23c3fd9386521ec9254943bff2a0d.png)
[games101] class note 8 - shading (shading frequency, graphics pipeline, texture mapping)
![[leetcode 7 solution] integer inversion](/img/72/b358a67eaedda48e1c0aebdaec04a5.jpg)
[leetcode 7 solution] integer inversion
随机推荐
Fcpx tutorial, how to export video graphics and text in Final Cut Pro?
synchronized下的 i+=2 和 i++ i++执行结果居然不一样
Golang type assertion understanding [go language Bible]
Dynamic memory management
Centos7 installing PHP
测试人如何规划自己的未来?才能实现入行2年达到25k?
服务端口不通排查
Design rule check constraint (set_max_transition, set_max_capability)
Scala基础语法入门(三)Scala中的各种运算符
Restful API 接口规范
20 shortcut keys for vs code!
SPI one master and many slaves
EditText control starts from the upper left corner
The joint empowerment plan of Baidu PaddlePaddle large enterprise open innovation center was launched! Help Pudong to upgrade its industry intelligently
Properties to YML
1. Getting to know R
检测当前系统语言
Connectez - vous à MySQL
EDI 855 purchase order confirmation
牛客網:三數之和