课程名称:一天时间高效准备前端技术一面 匹配大厂面试要求
章节名称:第5章 JS基础-原型和原型链
讲师:双越
主要包括3个知识点
class jQuery { constructor(selector) { const result = document.querySelectorAll(selector) const length = result.length for (let i = 0;i<length; i++) { this[i] = result[i] } this.length = length this.selector = selector } get(index) { return this[index] } each(fn) { for (let i=0; i<this.length; i++) { const elem = this[i] fn(elem) } } on(type, fn) { return this.each(elem => { elem.addEventListener(type, fn, false) }) } } // 扩展DOM API // 插件 jQuery.prototype.dialog = function (info) { ... } //“造轮子” class myJQuery extends jQuery { constructor(selector) { super(selector) ... } }