【发布时间】:2017-03-09 19:36:23
【问题描述】:
假设我有两个文件 front.js 和 other.js。我需要在 front.js 中添加 other.js 的代码
front.js -
// blah
var obj= {
a: function(){
// more blah
},
b: function(){
// more blah
},
/*
get
c: function(){
// more blah
},
here
*/
d: function(){
// more blah
}
};
// blah
其他.js -
c: function(){
// more blah
},
// this ^^ is all that there is in the file (invalid js)
如何在front.js 的正确位置导入other.js 中的代码?
【问题讨论】:
-
c: 46,是无效的 javascript,因此您无法命名文件other.js。一种选择是使other.js成为一个导出值的模块,然后在front.js中引用它。但是您似乎需要即时组装js代码,但是如果没有其他详细信息,很难说出您要做什么 -
c: 46,是无效的 js,是的,我知道。我正在查看一个具有不同 js 文件(不一定是有效的 js)的项目,如果将它们连接在一起,这将是有效的 js。想要在不制作大 js 文件或将不同文件重构为适当模块的情况下对其进行调试!
标签: javascript module scope