我的代码可与所有其他模块一起使用,但是JBehaviour给了我这个问题,并且知道我在做什么错,因为看来我做对了一切
完全错误: 未捕获的TypeError:类扩展值#不是构造函数或null 在对象。 (C:\ Users \ etern \ Documents \ GameEngine \ src \ engine \ classes \ JBehaviour.js:3) 在对象。 (C:\ Users \ etern \ Documents \ GameEngine \ src \ engine \ classes \ JBehaviour.js:11)
test_game.js
const {Vector2, GameObject, Rigidbody2d, JBehaviour, Input} = require('./Core')
Core.js
//Structs
const Vector2 = require('./structs/Vector2')
//Classes
const GameObject = require('./classes/GameObject')
const Rigidbody2d = require('./classes/Rigidbody2d')
const JBehaviour = require('./classes/JBehaviour')
const Input = require('./classes/Input')
module.exports = {Vector2, GameObject, Rigidbody2d, JBehaviour, Input}
JBehaviour.js
const Behaviour = require('./Behaviour')
class JBehaviour extends Behaviour{
constructor(){
super('JBehaviour')
}
}
module.exports = JBehaviour
Behaviour.js
const Component = require('./Component')
class Behaviour extends Component{
constructor(name){
super(name)
this.enabled = true
}
}
Component.js
const OBJ = require('./Object')
class Component extends OBJ {
constructor(name){
super(name)
this.gameObject = null
this.tag = null
this.transform = null
}
AssignGameObject(gameObject){
this.gameObject = gameObject
this.tag = gameObject.tag
this.transform = gameObject.transform
}
CompareTag(tag){
return (this.tag === tag)
}
}
module.exports = Component
Object.js
class OBJ{
constructor(name){
this.name = name
}
static Destroy(object){
delete object.name
}
static Instantiate(original){
return new OBJ(original.name)
}
ToString(){
return toString(this.name)
}
}
module.exports = OBJ
答案 0 :(得分:1)
您没有导出Behaviour
,因此require('./Behaviour')
返回的值是一个空对象。空对象不能从中扩展。
导出Behaviour
就像处理JBehaviour
一样:
module.exports = Behaviour