当前位置:网站首页>JS实现链式调用
JS实现链式调用
2022-07-07 08:26:00 【xinxin_csdn】
可用链式方法实现四则运算
/* 简单的链式调用 类实现*/
class Person{
constructor(){
this.name = ''
}
setName(name) {
this.name = name
return this
}
getName() {
console.log('name:==',this.name)
}
}
const person = new Person()
person.setName('zx').getName()
/*函数实现*/
function Person() {
this.name = ''
}
Person.prototype = {
setName: function(name) {
this.name = name
return this
},
getName: function() {
console.log('name:==',this.name)
}
}
const person = new Person()
person.setName('zx').getName()
边栏推荐
- Study summary of postgraduate entrance examination in July
- 优雅的 Controller 层代码
- Fiddler break point
- Review of the losers in the postgraduate entrance examination
- Methods of adding centerlines and centerlines in SolidWorks drawings
- Download Text, pictures and ab packages used by unitywebrequest Foundation
- 大整数类实现阶乘
- 1321:【例6.3】删数问题(Noip1994)
- 原型与原型链
- 移动端通过设置rem使页面内容及字体大小自动调整
猜你喜欢
The method of word automatically generating directory
Weekly recommended short videos: what are the functions of L2 that we often use in daily life?
字符串格式化
The variables or functions declared in the header file cannot be recognized after importing other people's projects and adding the header file
ThreadLocal会用可不够
Methods of adding centerlines and centerlines in SolidWorks drawings
小程序跳转H5,配置业务域名经验教程
P2788 数学1(math1)- 加减算式
Use of JSON extractor originals in JMeter
Prototype object in ES6
随机推荐
Chris Lattner, père de llvm: Pourquoi reconstruire le logiciel d'infrastructure ai
Multisim--软件相关使用技巧
【华为机试真题详解】高矮个子排队
Guid主键
Use the fetch statement to obtain the repetition of the last row of cursor data
The story of Plato and his three disciples: how to find happiness? How to find the ideal partner?
Trajectory planning for multi robot systems: methods and Applications Overview reading notes
求最大公约数与最小公倍数(C语言)
Talking about the return format in the log, encapsulation format handling, exception handling
Kotlin realizes wechat interface switching (fragment exercise)
Programming features of ISP, IAP, ICP, JTAG and SWD
电表远程抄表拉合闸操作命令指令
串口通讯继电器-modbus通信上位机调试软件工具项目开发案例
Prototype and prototype chain
About hzero resource error (groovy.lang.missingpropertyexception: no such property: weight for class)
Leetcode exercise - 113 Path sum II
. Net configuration system
Some superficial understanding of word2vec
搭建物联网硬件通信技术几种方案
【STM32】STM32烧录程序后SWD无法识别器件的问题解决方法