随笔分类 - js
摘要:let sort = (arr, callback) => { for (let i = 0; i < arr.length; i++) { for (let j = 0; j < arr.length; j++) { if (callback(arr[i], arr[j]) > 0) { let
阅读全文
摘要:function dateOperation(date = new Date()) { this.myDate = new Date(date); // 格式化时间 this.getFormat = (format = 'YYYY-MM-DD HH:mm:ss', date = this.myDat
阅读全文
摘要:var a = Object.prototype.toString; console.log(a.call(2));console.log(a.call(true));console.log(a.call('str'));console.log(a.call([]));console.log(a.c
阅读全文
摘要:function numberFormat(value) { let param = {}; let k = 10000; let sizes = ['', '万', '亿', '万亿']; let i; if (value < k) { param.value = value; param.uni
阅读全文
摘要:function arrRemoval(s, id) { let setMap = new Map(); let arr = []; for (const sElement of s) { if (setMap.get(sElement[id]) !== 1) { setMap.set(sEleme
阅读全文
摘要:function throttle(fn, delay) { let lastTime; let timer; delay = delay || 300; return function() { let args = arguments; // 记录当前函数触发的时间 let nowTime = D
阅读全文
摘要:function debounce(fn, delay = 300) { //默认300毫秒 let timer; return function() { let args = arguments; if (timer) { clearTimeout(timer); } timer = setTim
阅读全文
摘要:function getBeforeDate(n) { let d = new Date(); let calculation = 1000 * 60 * 60 * 24 * n; let getTimeStr = new Date().getTime(); let date = new Date(
阅读全文
摘要:function getRandomNum(m, n) { return Math.floor(Math.random() * (m - n) + n);}
阅读全文
摘要:// 网上找的链接忘了、function deepCopy(obj) { if (typeof obj !== 'object') { // 对基本类型进行判断 return obj; } else if (Object.prototype.toString.call(obj) '[object N
阅读全文
摘要:if (!Array.prototype.map) { Array.prototype.map = function(callback) { var T, A, k; if (this == null) { throw new TypeError('this is null or not defin
阅读全文
摘要:/* jquery版本随意 *//* html2canvas 0.5.0-beta3 <http://html2canvas.hertzen.com> *//* http://www.phpied.com/rgb-color-parser-in-javascript/ *//* http://dem
阅读全文
摘要:let TILE_SIZE = 256;/* 传入经纬度和地图层级获取像素坐标 */let project = (lat, lng, zoom) => { let siny = Math.sin(lat * Math.PI / 180); siny = Math.min(Math.max(siny,
阅读全文
摘要:reduce //计算数组内值得和 filter //对数组进行筛选 let index = arr.map(item => item.name).indexOf(name);//获取数组内数值为某个的时候的下标值
阅读全文
摘要:str.split("");//把字符串转成数组 arr.reverse();//把数组反转 arr.join("");//把数组转成字符串
阅读全文
摘要:Element.getBoundingClientRect() //返回元素的大小及其相对于视口的位置。 IntersectionObserver //监听元素是否到了当前视口的事件
阅读全文
摘要:const KEY_LEN=10;const KEY_COUNT=20;const CHARS='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789<>?,./;[]{}!@#$%^&*()_+'; let arr=[];fo
阅读全文