使用包含哪些线性工作?

时间:2015-05-06 15:28:50

标签: javascript node.js

我不明白,我想在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 '' '' '' '' ....

// ...

但是当我这样做时,我有错误,因为功能测试不存在,或者变量不存在......

我怎么能这样做? 谢谢

1 个答案:

答案 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." );
});