function Color(elem){
    this.elem=elem;
    this.color=["blue","#9b59b6","#f39c12","#1abc9c"];
    this.run=function(){
        setInterval(
            function(){
                console.log(this);
                let i=Math.floor(Math.random()*this.color.length);
                this.elem.style.backgroundColor=this.color[i];
            }.bind(this),
            1000
        )
    }

}
let obj=new Color(document.body);

 

posted on 2022-01-19 23:16  weakup  阅读(14)  评论(0编辑  收藏  举报