[英]Using modules in google closure compiler
我只是想让一个基本模块工作:
testA.js:
goog.module('foo');
exports.bar = function(){
console.log('here');
};
testB.js:
var bar = goog.require('foo.bar');
bar();
我正在跑步:
java -jar ~/Downloads/compiler.jar --js testA.js testB.js
产量:
testB.js:1: ERROR - Closure dependency methods(goog.provide, goog.require, etc) must be called at file scope.
var bar = goog.require('foo.bar');
^
1 error(s), 0 warning(s)
有什么建议?
自己回答这个问题。 因此,您不能通常从“普通”闭包编译的.js
文件中获取模块,只能从模块文件中获取,模块文件似乎被定义为其中包含goog.module
任何文件。
所以如果在模块中, goog.require('module')
工作正常。 如果不在模块中,则需要goog.module.get('module')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.