function fangdou(delay, time) {
let timer
return function () {
if (!timer) { timer = setTimeout(delay, time) }
else {
clearTimeout(timer)
timer = setTimeout(delay, time)
}
}
}
function input() {
console.log(5555);
}
const test = fangdou(input, 10000)
test()
test()
test()
test()
节流
function jieliu(delay,time) {
let timer
return function () {
if (!timer) {
timer=setTimeout(delay,time)
}
}
}
function input() {
console.log(5555);
}
const test = jieliu(input, 10)
test()
test()
test()
test()
instanceof
function myInstanceOf(obj,cons){
let proto=Object.getPrototypeOf(obj)
while(proto){
if(proto==cons.prototype) return true
proto=Object.getPrototypeOf(proto)
}
return false
}
function Person(name) {
this.name = name;
}
let person = new Person('Alice');
console.log(myInstanceOf(person, Person)); // 输出 true