I see this line of code a lot in the JsMoonWarriors example? What exactly does it do?
That depends on which function this _super
have been invoked.
For example, if in init
function of MyLayer, _super
signify the overrided init
function of cc.Layer
var MyLayer = cc.Layer.extend({
init : function () {
this._super();
}
})
Yeah it’s usually used in the init function when extending cc.Layer. For example this code is from the AboutLayer.js:
var AboutLayer = cc.Layer.extend({
init:function () {
var bRet = false;
if (this._super()) {
My question is why is it wrapped in if(), it is obviously asking if _super() is returning true or not, why is it doing that?
That signify whether the super’s init have succeeded, if yes, it will continue the initialization process, otherwise it will abandon.