Open kosmosR2 opened 6 years ago
I think i catch the error.
When scene.onEnter()
called,this._super()
will be called.TypeError: this._super is not a function
will be thrown in compiled scene file.
It works fine if i use cc.Scene.prototype.onEnter.call(this)
to replace this._super()
.
From line 248 of cocos2d-x/cocos/scripting/js-bindings/script/jsb_prepare.js
:
fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
// Copy the properties over onto the new prototype
for (name in prop) {
// Check if we're overwriting an existing function
prototype[name] = typeof prop[name] == "function" &&
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
(function (name, fn) {
return function () {
var tmp = this._super;
// Add a new ._super() method that is the same method
// but on the super-class
this._super = _super[name];
// The method only need to be bound temporarily, so we
// remove it when we're done executing
var ret = fn.apply(this, arguments);
this._super = tmp;
return ret;
};
})(name, prop[name]) :
prop[name];
You guys may want use fnTest.test
to check if the method going to call this._super
.Maybe this issue will not happen if we compile all jsb code...
But my suggestion is to remove fnTest.test(prop[name])
.I don't think it is necessary.
Can confirm that this issue does not happen if the frameworks/cocos2d-x/cocos/scripting/js-bindings/script/
folder is also jscompile
-d
Steps to Reproduce:
cocos jscompile -s path/to/src -d path/to/src
cocos run -p linux/android
cocos
command line tool just now(and sure it works fine before we compile its js code),main.js
can't take us toHelloWorldScene
.And no error will be thrown.I can get a instance ofHelloWorldScene
class and access its attributes correctly whilecc.director
can't make use of the instance.