当前位置:网站首页>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()边栏推荐
- Programming features of ISP, IAP, ICP, JTAG and SWD
- C logging method
- Methods of adding centerlines and centerlines in SolidWorks drawings
- Study summary of postgraduate entrance examination in November
- 【剑指Offer】42. 栈的压入、弹出序列
- Factorial implementation of large integer classes
- Guid主键
- 浅谈日志中的返回格式封装格式处理,异常处理
- 对存储过程进行加密和解密(SQL 2008/SQL 2012)
- 【华为机试真题详解】高矮个子排队
猜你喜欢

Fiddler simulates the interface test

Leetcode-304: two dimensional area and retrieval - matrix immutable

【剑指Offer】42. 栈的压入、弹出序列

leetcode-304:二维区域和检索 - 矩阵不可变

Review of the losers in the postgraduate entrance examination

成为优秀的TS体操高手 之 TS 类型体操前置知识储备

STM32 ADC和DMA

【acwing】789. Range of numbers (binary basis)

Several schemes of building hardware communication technology of Internet of things

【acwing】786. Number k
随机推荐
Download Text, pictures and ab packages used by unitywebrequest Foundation
Postman interface test VI
Guide de signature du Code Appx
OpenGL glLightfv 函数的应用以及光源的相关知识
Review of the losers in the postgraduate entrance examination
移动端通过设置rem使页面内容及字体大小自动调整
leetcode-303:区域和检索 - 数组不可变
Factorial implementation of large integer classes
Leetcode-560: subarray with sum K
Why is the reflection efficiency low?
[higherhrnet] higherhrnet detailed heat map regression code of higherhrnet
Hdu-2196 tree DP learning notes
@Configuration, use, principle and precautions of transmission:
【acwing】789. 数的范围(二分基础)
How to cancel automatic saving of changes in sqlyog database
Leetcode exercise - 113 Path sum II
宁愿把简单的问题说一百遍,也不把复杂的问题做一遍
LLVM之父Chris Lattner:為什麼我們要重建AI基礎設施軟件
Smart city construction based on GIS 3D visualization technology
2022.7.5DAY597