简体   繁体   English

我想使javascript库功能不起作用

[英]I wanted to make a javascript library function is not working

I wanted to call the run function that should call the other and action will be done on the base of element_id 我想调用应该调用另一个函数的run函数,然后在element_id的基础上执行操作

 NGL = {}
NGL.SceneBuilder = function() {

  var yamlFile = 'http://example.com/main.yaml'
  var parseYaml = function() {
  }
  var buildScene = function() {
    // other code

    simulationStarted(element_id);
  }

  return {
    run: function(element_id) {
      parseYaml();
      buildScene(element_id);

    }
  }

}
NGL.SceneBuilder.run('#someid');

You're not executing your factory so NGL.SceneBuilder is a function, not an object having the run property. 您没有执行工厂,因此NGL.SceneBuilder是一个函数,而不是具有run属性的对象。 Call the function : 调用函数:

NGL.SceneBuilder = (function() {

  ...

})(); // <<===

Note also that you forget to declare the element_id parameter in buildScene but maybe is it just for the question. 还要注意,您忘了在buildScene声明element_id参数,但这也许只是为了解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM