1、new关键字做了什么
1、创建一个新对象
2、将对象的__proto__指向构造函数的prototype
3、使用给定的参数执行构造函数,将this指向新对象 4、判断返回值类型,如果是值类型,则返回新对象,如果是引用类型,则返回这个引用类型的对象
function mayNew(fn, ...args) {
const constructor = fn;
const obj = Object.create(constructor.prototype);
const result = constructor.apply(obj, args);
if (
(typeof result === "object" && result !== null) ||
typeof result === "function"
) {
return result;
} else {
return obj;
}
}
2、图片懒加载
3、EventEmitter
4、虚拟滚动
5、节流和防抖
6、call、apply和bind
7、width:100% 与 width:auto区别
auto:浏览器将会为指定的元素计算并选择一个宽度,会自动撑满父元素
8、二叉树遍历
9、快排