0

I'm using mootools 1.6. I based my code on their tutorial but when I try to run it, the initialize function of my subclass is not invoked. Instead, it goes directly to the parent class' initialize function. I tried breakpointing inside the subclass initialize function but it really doesn't go there. In fact, my additional functions are also undefined. It's like only the functions of the parent class are created. :(

Here's my sample code:
parent.js

   var Parent = new Class({

    initialize: function(){
        alert("parent");
    },
    ...

});


child.js

var Child = new Class ( {
    Extends: Parent, 
    initialize: function () {
        this.parent();
        alert("child");
    },
    ... some additional functions
});


1.) Note that they are in different js files.
2.) These files are preloaded by cocos2d-js

    ...
    "src/controllers/parent.js",
    "src/controllers/child.js",
    ...
4

1 回答 1

2

我能够解决这个问题。Mootools 没有问题。我就是这样使用它的。我将它发布给可能遇到相同问题的人。

我有 3 个 js 文件。

parent.js
child.js
orphan.js (calling it orphan hahaha)

这 3 个文件按此顺序添加到 project.json。我没有使用orphan.js. 我以为我已经从列表中删除了它,但我错了。:(

里面orphan.js,是一个类。此类使用与内部类相同的名称child.js。它是空的,只是在扩展父级。发生的事情是,它重新定义了对象,因为它是在child.js. 我改变了他们的顺序,看看它是否会使用child.js声明,确实如此。但这不是解决方案。我只是用它来证明它被重新定义了。解决方案是从源中删除该文件/确保没有类具有相同的名称。

唷。虚惊。

于 2016-02-04T06:18:10.397 回答