我正在开发一个具有以下特征的前端javascript项目:
第三点是我提出这个问题的主要原因,因为当我研究如何在客户端组织javascript时,答案通常包括一些服务器端库。我无法访问此内容。我想将我的课程保存在一个文件夹(可能是一些子文件夹),一个主脚本和另一个带有第三方库的文件夹中。然而,我还没有找到一种很好的方法。
我在我的一个html文件中尝试过这样做:
<!-- include 3rd party librayA -->
<!-- include 3rd party librayB -->
<!-- include classA script -->
<!-- include classB script -->
<!-- include main.js -->
但是main.js似乎并不知道这些类是什么。
理想情况下,我喜欢需要的东西,但是,我发现任何类似的东西都使用了我无法使用的服务器端技术。
以下是我尝试的简化形式:
./ index.html的:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script type="test/javascript" src="./classes/TestClass.js"></script>
<script type="text/javascript" src="./script.js"></script>
</head>
<body>
</body>
</html>
./的script.js
var testClassInstance = new TestClass("test!");
testClassInstance.bar();
./类/ TestClass.js
var TestClass = function (foo) {
this.foo = foo;
};
TestClass.prototype.bar = function () {
console.log(this.foo);
}
我得到的错误是:
script.js:1 Uncaught ReferenceError: TestClass is not defined(…)