首页 > 解决方案 > 导入纯 JS 文件

问题描述

我试图让我的文件尽可能基本。因此,在我的 html 文件中,我有:

<script src="js/binarytree_standardgrid_script.js"></script>

然后在我的binarytree_standardgrid_script.js文件中我想使用:Ramda.js

如何在不使用节点的情况下“导入”Ramda.js或“包含” ?Ramda.js还是我真的需要使用节点?

然后我有另一个文件叫做BinaryTree.js

文件结构为

    ./index.html 
    ./algorithms/BinaryTree.js
    ./js/binarytree_standardgrid_script.js

在我调用的html文件中binarytree_standardgrid_script.js

在该脚本中,我希望能够使用BinaryTree.js,然后还可以使用 Ramda 库。

我怎样才能在 Javascript 中做到这一点?我真的需要使用节点吗?

标签: javascriptimportramda.js

解决方案


好的,我找到了解决方案:

只需将脚本放在 html 页面上:

<script src="algorithms/BinaryTree.js"></script>

<script src="http://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>

<script src="js/binarytree_standardgrid_script.js"></script>

只要不在函数内,这些类和函数就可以在脚本文件中使用。


推荐阅读