
获得徽章 8
请教一下这里为什么要这样写呢?
function extend (child, parent) {
var F = function () {};
F.prototype = parent.prototype;
child.prototype = new F();
child.prototype.construtor = child;
// ? 实在不知道这里为什么要这样
child.parent = parent.prototype;
if(!parent.prototype.contrucotor == Object.prototype.constructor){
parent.prototype.constructor = parent;
}
}展开赞过121请教一下这里为什么要这样写呢?
function extend (child, parent) {
var F = function () {};
F.prototype = parent.prototype;
child.prototype = new F();
child.prototype.construtor = child;
// ? 实在不知道这里为什么要这样
child.parent = parent.prototype;
if(!parent.prototype.contrucotor == Object.prototype.constructor){
parent.prototype.constructor = parent;
}
}展开评论点赞- 关于函数防抖的几个问题:
1. 为什么要使用闭包,返回一个function呢?
2. 为什么要使用fn.call(_this, _args) 改变this指向,不用的话有什么问题?
function debounce(fn, delayTime) {
let timer = null
return function (args) {
if (timer) {
timer = null
clearTimeout(timer)
}
let _this = this
let _args = args
timer = setTimeout(function () {
fn.call(_this, _args)
}, delayTime)
}
}
let inputDom = document.getElementById('input2')
inputDom.addEventListener('keyup', debounce((e) => {console.log(e.target.value)}, 1000))展开等人赞过35