如何使用从 javascript 中的函数返回的外部库对象的属性?

How can I use properties of external library object that returned from a function in javascript?

我正在使用 createjs 制作 html5 游戏,但这部分代码存在问题:

function createGameObj(){
   var text = new createjs.Text("Some Text","16px Arial","white");
   var container = new createjs.Container();
   container.addChild(text);
   return container;
}

我有一个像上面那样的功能。当我调用它并获取从它返回的对象时,我无法使用它的属性。

function prepareGameStage(){
   var obj = createGameObj(); //It should be typeof createjs.Container when we do typecasting which we get used to see at oop
   obj.x = canvas.width/2; //this doesnt make any errors but also doesnt work. So I cant access "x" property of "createjs.Container" type object.
   stage.addChild(obj); //error occurs here because of undefined type of obj. 
}

我试过像这样投射 obj:

obj = Object.create(createjs.Container,createGameObj());

但是没用。

你们有什么解决办法吗?

好的,我解决了。就像 Bergi 说我在另一个 statement.My createGameObj 上犯了一个错误就像:

function createGameObj(){
   var text = new createjs.Text("Some Text","16px Arial","white");
   var container = new createjs.Container();
   container.addChild(text);
   function(event){
      //do some here
      return container;
   }
}

并且它return将容器对象编辑为 createGameObj function.And 因为 createGameObj 函数还没有 return 声明它 return 编辑 'undefined' 作为默认.我意识到它很晚:)。删除嵌套函数并解决。