13.桥接模式

85 阅读1分钟
 function Color(clr) {
        this.clr = clr 
    }
    Color.prototype.draw = function() {
        console.log('draw',this.clr)
    }
    function Shape(shp) {
        this.shp = shp
    }
    Shape.prototype.change = function() {
        console.log('shape')
    }
    function Unit() {
        this.color = new Color('red')
        this.shape = new Shape('shape')
    } 
    Unit.prototype.init = function() {
        this.color.draw()
        this.shape.change()
    }
    var smallUnit = new Unit('blue','wawaawlala')