1.在看vue源码相关的帖子中看到这个函数:
class Dep () {
constructor () {
this.subs = [];
}
addSub (sub: Watcher) {
this.subs.push(sub)
}
removeSub (sub: Watcher) {
remove(this.subs, sub)
}
notify () {
// stabilize the subscriber list first
const subs = this.subs.slice()
for (let i = 0, l = subs.length; i < l; i++) {
subs[i].update()
}
}
}
这里的Watcher也是一个class对象,那么这里的(sub: Watcher)是一个键值对?那不是应该要有中括号吗?还是我理解岔了?
JS 里暂时还没有静态类型,这里应该是 TypeScript 或者 Flow 吧?