javascript new调用构造函数
2023-03-15 23:18:56 时间
1、内存中创建新的对象。
2、新对象的prototype特性被赋值为构造函数的属性。
3、this指向构造函数新对象。
4、执行构造函数的代码。
为新对象添加属性。
5、构造函数没有返回对象,则返回新对象。
实例
/除了声明函数也可以写成表达式 //Let Person=function (name,age){ function Person(name,age){ //let o=new Object(); this.name=name; this.age=age; this.sayName=function(){ console.log(this.name); }; //return o; } Person.prototype=[]; let p1=new Person("Greg",27); console.log(Person.prototype); console.log(p1.prototype); console.log(p1);
以上就是JavaScript new调用构造函数的方法,希望对大家有所帮助。更多Javascript学习指路:Javascript
相关文章
- 盘点4种使用Python批量合并同一文件夹内所有子文件夹下的Excel文件内所有Sheet数据
- OushuDB 学习经验分享(三):技术特点
- Java和Python思维方式的不同之处
- Python中日志记录新技能
- 奥比中光Gemini OpenCV—Python使用
- python与分形0008 - 圈圈
- Python自动打码,DdddOcr通用验证码自动识别库
- python与分形0009 - 谢尔宾斯基地毯
- python与分形0010 - 圆形螺旋
- 一篇文章带你搞定Python中logging模块
- 一篇文章带你搞定Python中urllib库(操作URL)
- Nebula Graph 源码解读系列 | Vol.05 Scheduler 和 Executor 两兄弟
- 创建一个 Python 应用程序来衡量客户终身价值 (CLV)
- 2021 年 Python 的好与坏
- Python推测图片格式
- SpringMvc简单梳理
- Salesforce Batch Apex 批处理(一)
- 攻防世界pyc-trade
- 什么是内存乱序访问?
- 手把手教你用Python提取PDF中的表格