SOURCE

console 命令行工具 X clear

                    
>
console
class Dep {
    constructor(){
        this.subs = []
    }

    addSub(sub){
        this.subs.push(sub)
    }

    removeSub(sub){
        remove(this.subs, sub)
    }

    depend(){
        if(window.target){
            this.addSub(window.target)
        }
    }

    notify(){
        const subs = this.subs.slice()
        for(let i=0; i< this.subs.length; i++){
            subs[i].update()
        }
    }
}

function remove(arr, item){
    if(arr.length){
        const index = arr.indexOf(item)
        if(index > -1){
            return arr.splice(index, 1)
        }
    }
}
<html>
    <head>

    </head>
    <body>
        <p>Dep类的封装</p>
    </body>
</html>

本项目引用的自定义外部资源