当前位置:网站首页>new做了哪几件事
new做了哪几件事
2022-06-12 20:29:00 【站在桥上烤冷面】
- 创建了一个空对象
- 让子对象自动继承构造函数的原型对象
- 调用构造函数,替换实参,将this替换为正在创建的新对象
- 将新对象的内存地址返回
优点: 重用对象结构代码
缺点: 如果构造函数中包含方法定义,则每次创建新对象都会重复创建相同方法的副本。——浪费内存!
解决:如果发现多个子对象都需要使用相同的功能时,就可以使用继承来解决
什么是继承?父对象中的成员,子对象无需重复创建就可以直接使用,就像使用自己的成员一样
JS中的继承都是通过原型对象来实现的
什么是原型对象?替所有子对象集中保存共有的属性和方法的特殊父对象
如何:创建原型对象:不用自己创建,而是在定义构造函数时,程序自动为我们生成。
找到原型对象?构造函数中都有一个自带属性prototype,指向自己匹配的原型对象即:构造函数.prototype
向原型对象中添加共有的属性和方法构造函数.prototype.共有方法 = function(){}
构造函数.prototype.共有属性=属性值
今后,用子对象.访问对象的成员时,js引擎先在子对象内部查找自有的属性。如果子对象没有,则js引擎会自动延_ _proto_ _属性去父元素查找。如果在父元素中找到了想要的属性或方法,则和访问子对象的方法一样调用。
边栏推荐
- 部署static pod方式部署etcd集群
- 使用Swagger生成 API 文档(go语言示例)
- Microsoft Word tutorial, how to insert a header or footer in word?
- Unsupported class file major version 60
- What is an index?
- Scalars, vectors, arrays, and matrices
- golang类型断言理解[go语言圣经]
- P5076 [deep base 16. Example 7] common binary tree (simplified version)
- How mysterious is "PIP not an internal or external command, nor a runnable program or batch file"
- The new colleague asked me what "where 1=1" means???
猜你喜欢
Design rule check constraint (set_max_transition, set_max_capability)
2022年春招,测试工程师全套面试攻略,一篇吃透全部技术栈(全是干货)
没有学历,自学软件测试,找到一份月入过万的测试工作真的有可能吗?
A simple understanding of consistent hash
[leetcode] small thinking of optimal division
Viewpoint sharing | Li Wei, an expert of Gewu titanium intelligent technology products: underlying logic and scenario practice of unstructured data platform
Lightroom Ambassador series: capturing nostalgia with MEG loeks
Test prerequisites: recommend a special cross platform app performance test tool!
Overview of object detection
Nexus3搭建本地仓库
随机推荐
Macro definitions and functions
Generate API documents using swagger (go language example)
Niuke net: somme des trois nombres
Design rule check constraint (set_max_transition, set_max_capability)
golang类型断言理解[go语言圣经]
How to determine fragment restored from Backstack
P5076 【深基16.例7】普通二叉樹(簡化版)
Connectez - vous à MySQL
Installation of xv6 system
MySQL - the execution order of an SQL statement
Blue Bridge Cup basic-15 VIP question string comparison
The Milvus graphical management tool Attu is coming!
MinIO客户端(mc命令)实现数据迁移
Nexus3搭建本地仓库
UVa11991 Easy Problem from Rujia Liu
Why can't fields with high duplicate values be indexed (such as gender fields)
Properties to YML
1. Getting to know R
Is online futures account reliable? Is it safe to open an online futures account?
Deploy etcd cluster in static pod mode