随笔分类 - javascript
摘要:es6只有findIndex,业务需要从尾部查找,自己实现一个findLastIndex /** * 数组原型添加findLastIndex */ (Array.prototype as any)._jt_findLastIndex = function (callback) { try { if
阅读全文
摘要:/** * 删除url的指定参数 * @param {*} url 需要处理的url * @param {*} name 参数名称 */ export const deleteQueryString = (url, name) => { try { const re = new RegExp('&?
阅读全文
摘要:给dom添加额外信息,当dom移除,自动清除 <!DOCTYPE html> <html lang="en"> <body> <button id="btn">btn</button> <script> let wm = new WeakMap(); // console.log('window.b
阅读全文
摘要:<!DOCTYPE html> <html lang="en"> <body> <button id="btn">箭头函数this</button> <script> let btn = document.getElementById("btn"); let obj = { name: "boy",
阅读全文
摘要:类新建的对象,执行是undefined class Animal { say() { console.log("say", this); } } let obj = new Animal(); let say = obj.say; say(); 字面量新建的对象,执行是window let obj
阅读全文
摘要:Array.prototype.myReduce = function (callback, prev) { for (let i = 0; i < this.length; i++) { if (typeof prev "undefined") { prev = callback(this[i],
阅读全文
摘要:利用javascript语言特性,预解析时this赋值点'.'的前面对象 Function.prototype.myCall = function (ctx, ...args) { ctx = ctx ? Object(ctx) : window; ctx.fn = this; //利用javasc
阅读全文