我不明白,我想在IoJS(NodeJS的分支)中使用include .js文件,例如:
// in file var.js:
var variableOne, variableTwo = {}, variable3 = [];
// in file function.js
function test(a, b){return a*b;}
// include module vehicle which use function test(), and my variable
// include module buildind '' '' '' '' ....
// ...
但是当我这样做时,我有错误,因为功能测试不存在,或者变量不存在......
我怎么能这样做? 谢谢
答案 0 :(得分:0)
Javascript不向您提供包含功能。 您应该使用HTML导入
<script src="filepath/filename.js"></script>
或使用一些更高级的技术,例如jQuery getScript。
$.getScript( "ajax/test.js", function( data, textStatus, jqxhr ) {
console.log( data ); // Data returned
console.log( textStatus ); // Success
console.log( jqxhr.status ); // 200
console.log( "Load was performed." );
});