为什么我的Backbone.View.constructor .__ super__不确定的,如果我用_.bindAll(本) [英] Why is my Backbone.View.constructor.__super__ undefined if I use _.bindAll(this)
问题描述
我继承我自己Backbone.View。如果在超类的初始化函数,我写的:
I am subclassing my own Backbone.View. If, in the super class' initialize function, I write:
_ bindAll(这一点,多,方法);
_.bindAll(this, 'many', 'methods');
,并指定我想绑定到这个上下文中的方法,我可以超级从子类通过调用:
And specify the methods that I want to bind to this context, I can call super from the subclass via:
this.constructor.__super__.initialize.apply(this, arguments);
但是,如果在超类中,我使用的:
But, if in the super class, I use:
_.bindAll(this)
相反,当我去从我的子类调用super,
instead, when I go to call super from my subclass,
this.constructor.__super__
是不确定的。为什么这是任何智慧?
is undefined. Any wisdom on why that is?
推荐答案
为什么不干脆用它来调用超:
Why not simply use this to call the super:
(我要分开几行澄清,你可以在一个线路的呼叫)
(I am separating to several lines for clarification, you can do the call in one line)
var thisProto = Object.getPrototypeOf(thisInstance);
var superProto = Object.getPrototypeOf(thisProto);
superProto.superMethod.apply(thisInstance, [param1, param2]);
这篇关于为什么我的Backbone.View.constructor .__ super__不确定的,如果我用_.bindAll(本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!