js 工具
2022/5/4 23:18:39
本文主要是介绍js 工具,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
/** | |
* @description 金额运算 | |
* @param { '+' | '-' | '*' | '/' } method 计算方法 | |
* @param { string | number} args 需要参与计算的数值或字符串 | |
* @return { number } 计算后的值 | |
*/ | |
const operation = (method, ...args) => { | |
const arr = args.map((item) => parseInt((item *= 100))); | |
let num = 0; | |
switch (method) { | |
case '+': | |
num = arr.reduce((total, item) => total + item) / 100; | |
break; | |
case '-': | |
num = arr.reduce((total, item) => total - item) / 100; | |
break; | |
case '*': | |
num = arr.reduce((total, item) => (total * item) / 100, 1); | |
break; | |
case '/': | |
num = arr.reduce((total, item) => (total * 100) / item) / 100; | |
break; | |
} | |
return num; | |
}; | |
/** | |
* @description 防抖 | |
* @param { function } handler 触发的函数 | |
* @param { number } delay 时间 | |
*/ | |
const debounce = (handler, delay) => { | |
let timer; | |
return function () { | |
let _this = this; | |
clearTimeout(timer); | |
timer = setTimeout(function () { | |
handler.apply(_this, arguments); | |
}, delay); | |
}; | |
}; |
这篇关于js 工具的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-07-26原创自研vue3 setup+arco.design网页版webos系统
- 2024-07-17Vue如何实现数据的上移和下移
- 2024-07-16组长:你熟悉过React,开发个Next项目模板吧,我:怎么扯上关系的?
- 2024-07-16React NextJS App Router 实时获取API
- 2024-07-16首创vite5.x+vue3+elementPlus仿微信web版聊天
- 2024-07-16electron31+vue3桌面聊天exe系统
- 2024-07-15python项目导入上级目录设置”的setting.json是不是哪里还有错误呀?
- 2024-07-06vue 新建功能多条数据(还没和后端交互)还能看详情 数据是前端缓存到本地吗?-icode9专业技术文章分享
- 2024-05-30React Native常用组件-点击组件
- 2024-05-30uniapp+vue3+uv-ui手机端后台OA管理模板