判断是不是DOM元素

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 function isElement(obj: any) { try { // Using W3 DOM2 (works for FF, Opera and Chrome) return obj instanceof HTMLElement; } catch (e) { // Browsers not supporting W3 DOM2 don't have HTMLElement and // an exception is thrown and we end up here. Testing some // properties that all elements have (works on

Classname Operation

操作相关classname工具函数 1 2 3 4 5 6 7 8 9 10 11 // 增加目标class function addClass(target = '', srcCls = '') { const clss = target.split(/\s+/) return [...clss.filter(cls => !clss.includes(cls)), srcCls] } function removeClass(target = '', srcCls = '') { const clss = target.split(/\s+/) return [...clss.filter(cls

防抖与节流

no-refresh-page history.pushState( {}, null, this.$route.path + ‘#’ + encodeURIComponent(params) )

HTML Element API 用法

Element.append 方法在 Element的最后一个子节点之后插入一组 Node 对象或 DOMString 对象。 被插入的 DOMString 对象等价为 Text 节点。 Element.append((Node or DOMString)… nodes); 示例代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14

常用判断函数

是否是promise 1 2 3 export function isPromise(object: any): object is Promise<any> { return Promise.resolve(object) === object; }

Linux 常用命令

查看端口占用 lsof -i tcp:80 所有端口 netstat -ntlp 查看端口进程 netstat -lnp|grep 端口号 netstat -anp|grep 端口号 Linux内核版本命令 cat /proc/version uname -a 查看Linux系统版本的命令 lsb_release -a cat /etc/redhat-release cat

BaseFindIndex

baseFindIndex 查找数组中的索引 1 2 3 4 5 6 7 8 9 10 11 function baseFindIndex(array, predicate, fromIndex, fromRight) { const { length } = array let index = fromIndex + (fromRight ? 1 : -1) while ((fromRight ? index-- : ++index < length)) { if (predicate(array[index], index, array)) { return index } } return -1 }

ArrayEach

ArrayEach实现循环 用while中的break实现原来Array.prototype.forEach未实现的打断功能 1 2 3 4 5 6 7 8