您可以自己制作
Controls一个类:
var Controls = function (controllable_object) { this.ref = controllable_object;};Controls.prototype.next = function () { this.ref.foo();}// ..var Carousel = function () { this.controls = new Controls(this);};// ..这不允许您覆盖
Controls虽然的实现。有了更多的依赖注入,您将得到类似:
var Controls = function (controllable_object) { this.ref = controllable_object;};Controls.prototype.next = function () { this.ref.foo();}// ..var Carousel = function () { this.controllers = []; };Carousel.prototype.addController = function (controller) { this.controllers.push(controller); };// ..var carousel = new Carousel();carousel.addController(new Controls(carousel));


