当前位置:网站首页>详细解析js中的混合方式构造对象(构造加属性,原型加方法)
详细解析js中的混合方式构造对象(构造加属性,原型加方法)
2022-07-26 10:15:00 【Xaivor】
详细解析混合方式构造对象
js代码如下
function CreatePerson(name, qq) //用构造函数加属性
{
//原料 +new 系统偷偷替咱们做
//var obj=new Object(); var this=new Object();
//加工
this.name=name;
this.qq=qq;
//出厂 +new 还会偷偷做一些:
//return obj; return this;
};
CreatePerson.prototype.showName=function() //用原型加方法
{
alert('我的名字是:'+this.name);
};
CreatePerson.prototype.showQQ=function()
{
alert('我的QQ是:'+this.qq);
};
var obj=new CreatePerson('张三','123456789');obj.showName();obj.showQQ();
var obj2=new CreatePerson('李四','987654321');obj2.showName();obj2.showQQ();
//alert(obj.showName==obj.showName);
边栏推荐
- 面试突击68:为什么 TCP 需要 3 次握手?
- 网易云UI模仿-->侧边栏
- Study notes of the third week of sophomore year
- 服务发现原理分析与源码解读
- About automatic operation on Web pages
- 汉诺塔II|汉诺塔4柱
- Mqtt x cli officially released: powerful and easy-to-use mqtt 5.0 command line tool
- 如何写一篇百万阅读量的文章
- Phpexcel export Emoji symbol error
- Uni app learning summary
猜你喜欢

Flask框架初学-04-flask蓝图及代码抽离

Data communication foundation - layer 2 switching principle
![[MySQL database] a collection of basic MySQL operations - the basis of seeing (adding, deleting, modifying, and querying)](/img/a7/b3bb6f584dff0eb9b49e81e5b9dade.png)
[MySQL database] a collection of basic MySQL operations - the basis of seeing (adding, deleting, modifying, and querying)

Okaleido ecological core equity Oka, all in fusion mining mode

服务器内存故障预测居然可以这样做!

Due to fierce competition in the new market, China Mobile was forced to launch a restrictive ultra-low price 5g package

服务发现原理分析与源码解读
![[Qualcomm][Network] qti服务分析](/img/76/49054ff8c7215eca98cc479ab1d986.png)
[Qualcomm][Network] qti服务分析

Beginner of flask framework-04-flask blueprint and code separation

Common errors when starting projects in uniapp ---appid
随机推荐
Write a script that can run in Bash / shell and PowerShell
Sqoop [put it into practice 02] sqoop latest version full database import + data filtering + field type support description and example code (query parameter and field type forced conversion)
如何写一篇百万阅读量的文章
Study on the basis of opencv
[award-winning question] ask Judea pearl, the Turing prize winner and the father of Bayesian networks
SQL Server 2008 server engine failed to start?
服务发现原理分析与源码解读
Error in render: "typeerror: cannot read properties of undefined (reading 'length')" --- error when calling interface
Sqoop【付诸实践 02】Sqoop1最新版 全库导入 + 数据过滤 + 字段类型支持 说明及举例代码(query参数及字段类型强制转换)
Common errors when starting projects in uniapp ---appid
Wu Enda linear regression of machine learning
Use of selectors
Wechat H5 payment on WAP, for non wechat browsers
Set view dynamic picture
I finished watching this video on my knees at station B
PHP executes shell script
Installation and use of cocoapods
Okaleido生态核心权益OKA,尽在聚变Mining模式
分布式网络通信框架:本地服务怎么发布成RPC服务
SSG framework Gatsby accesses the database and displays it on the page