面向对象
三要素
封装
继承
多态
意义
数据结构化
👇
抽象 --> 简单
应用
jQuery中的应用
javascript
class jQuery {
constructor(selector) {
const slice = Array.prototype.slice
const $el = slice.call(document.querySelectorAll(selector))
const len = $el.length
for (let i = 0; i < len; i++) {
this[i] = $el[i]
}
this.selector = selector
this.length = len
}
addClass() {}
}
window.$ = function (selector) {
return new jQuery(selector)
}
const $h = $('h2')
console.log($h)
const $p = $('section')
console.log($p)
class jQuery {
constructor(selector) {
const slice = Array.prototype.slice
const $el = slice.call(document.querySelectorAll(selector))
const len = $el.length
for (let i = 0; i < len; i++) {
this[i] = $el[i]
}
this.selector = selector
this.length = len
}
addClass() {}
}
window.$ = function (selector) {
return new jQuery(selector)
}
const $h = $('h2')
console.log($h)
const $p = $('section')
console.log($p)