在下面的代码中,我this.lister
在create_components
方法中得到了未定义的引用。我试图理解this
(显然根据您调用该方法的方式而变化)的含义,但如果有人能指出为什么this
不绑定到的规则ScreenCreator
以及我如何实现这一点,那就太好了。
谢谢!
function ScreenCreator(config, container) {
this.lister = new Lister();
this.goldenlayout = new GoldenLayout(config, container);
this.create_components();
this.goldenlayout.init();
}
ScreenCreator.prototype.create_components = function() {
this.goldenlayout.registerComponent('comp1', function (container, state) {
this.lister.init(container, state);
});
}