1

我需要在初始化和渲染方法上执行一些代码,但据我所知,在使用卓别林时我不能直接修改它们——当我定义自己的初始化方法时,我的路由停止工作。

我也试过 afterInitialize() 但它似乎并不意味着被覆盖:https ://github.com/chaplinjs/chaplin/issues/168#issuecomment-8015915

4

1 回答 1

1

[...] 但据我了解,我不能在使用卓别林时直接修改它们

只要您适当地委托给扩展原型,您就可以直接修改它们。

由于您尚未标记您的问题javascriptcoffeescript,以下是每种解决方案的两种解决方案。首先是javascript。注意我们必须如何显式调用扩展函数。

var View = Chaplin.View.extend({
  initialize: function(options) {
    // Add code here ..

    // The below invokes the initialize function of the
    // base Chaplin.View class in the context of 
    // this class
    Chaplin.View.prototype.initialize.call(this, arguments);

    // .. or here
  }
});

接下来是coffeescript,这使得这种事情变得更加容易。

class View extends Chaplin.View
  initialize: ->
    // Add code here ..

    // The below auto-magically invokes the 
    // initialize method of the base class
    super

    // .. or here
于 2012-10-23T01:08:05.510 回答