JavaScript
我付出再多都不够
这个作者很懒,什么都没留下…
展开
-
reduce实现lodash中的get方法
const obj = { a: { b: [1, 2, 3] } } function get(target, str) { const path = str.replace(/\[/g, '.').replace(/\]/, '.').split('.') return path.reduce((pre, cur) =>...原创 2022-04-06 10:55:43 · 270 阅读 · 0 评论 -
js手写实现 call apply bind
// 手写实现call方法 Function.prototype._call = function (context = window, ...args) { // this指向函数调用者 此时指向原函数 context.callback = this; // 此时callback 调用时 this指向的是ctx(指向调用者) const result = ctx.callback(...args); delete contex...原创 2021-10-27 16:41:14 · 78 阅读 · 0 评论 -
js实现防抖和节流(简易版)
//防抖 function debounce(callback, time) { let timer = null; return function () { clearTimeout(timer); timer = setTimeout(() => { callback.apply(this, arguments); }, time); }; } //节流 function throttle(callback, time) { let time.原创 2021-10-27 14:57:11 · 150 阅读 · 0 评论 -
手写实现js中的new操作符
function create(constructor, ...args) { // 1.创建新对象 const target = {}; // 2.该对象的原型对象指向构造函数的原型 Object.setPrototypeOf(target, constructor.prototype); // 3.构造函数的this指向该对象 const result = constructor.apply(target, args);...原创 2021-10-27 14:27:20 · 100 阅读 · 0 评论 -
Vue导出指定内容PDF文件
Vue导出指定内容PDF文件 第一步 安装两个npm模块 第一个.将页面html转换成图片 npm install --save html2canvas 第二个.将图片生成pdf npm install jspdf --save 第二步 utils文件夹下创建一个htmlToPdf.js文件(文件名称和位置看个人喜好) // 导出页面为PDF格式 import html2Canvas from 'html2canvas' import JsPDF from 'jspdf' export def原创 2021-04-21 20:30:07 · 170 阅读 · 0 评论