当前位置:网站首页>详细解析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);
边栏推荐
- Use of selectors
- Spolicy request case
- Interview shock 68: why does TCP need three handshakes?
- SQL Server 2008 R2 installation problems
- Uniapp common error [wxml file compilation error]./pages/home/home Wxml and using MySQL front provided by phpstudy to establish an independent MySQL database and a detailed tutorial for independent da
- Draw arrows with openlayer
- Formwork (III)
- Write a script that can run in Bash / shell and PowerShell
- Data communication foundation - layer 2 switching principle
- MySQL 5.7.25 source code installation record
猜你喜欢

Mysql5.7.25 master-slave replication (one-way)

论文笔记(SESSION-BASED RECOMMENDATIONS WITHRECURRENT NEURAL NETWORKS)

About automatic operation on Web pages

Spolicy request case

AR model in MATLAB for short-term traffic flow prediction

点赞,《新程序员》电子书限时免费领啦!

Sqoop【环境搭建 01】CentOS Linux release 7.5 安装配置 sqoop-1.4.7 解决警告并验证(附Sqoop1+Sqoop2最新版安装包+MySQL驱动包资源)
![Sqoop [environment setup 01] CentOS Linux release 7.5 installation configuration sqoop-1.4.7 resolve warnings and verify (attach sqoop 1 + sqoop 2 Latest installation package +mysql driver package res](/img/8e/265af6b20f79b21c3eadcd70cfbdf7.png)
Sqoop [environment setup 01] CentOS Linux release 7.5 installation configuration sqoop-1.4.7 resolve warnings and verify (attach sqoop 1 + sqoop 2 Latest installation package +mysql driver package res

SSG framework Gatsby accesses the database and displays it on the page

Uniapp error 7 < Map >: marker ID should be a number
随机推荐
Unstoppable, pure domestic PCs have been in place, and the monopoly of the U.S. software and hardware system has been officially broken
SQL Server 2008 R2 installation problems
数据库的复习--3.SQL语言
What is the principle of reflection mechanism?
Study notes of the second week of sophomore year
Network related journals and conferences in CS
Okaleido生态核心权益OKA,尽在聚变Mining模式
[fluorescent character effect]
数通基础-二层交换原理
Solution of inputting whole line string after inputting integer
云原生(三十六) | Kubernetes篇之Harbor入门和安装
Study notes of the third week of sophomore year
The practice of OpenCV -- bank card number recognition
Common errors when starting projects in uniapp ---appid
How to use Gmail to pick up / send mail on Foxmail
Mysql5.7.25 master-slave replication (one-way)
Learning about opencv (1)
Sqoop【付诸实践 02】Sqoop1最新版 全库导入 + 数据过滤 + 字段类型支持 说明及举例代码(query参数及字段类型强制转换)
数通基础-TCPIP参考模型
Explain automatic packing and unpacking?