我只是想用另一个文件中的类创建一个对象,我已经尝试了几乎所有方法,但是控制台仍然给我同样的问题“未捕获的ReferenceError:未定义墙”,这是代码:
//sketch.js
let b
function setup(){
createCanvas(400,400);
b = new Wall(100,100,100,300);
}
function draw() {
background(0);
b.show();
}
文件位于同一文件夹
class Wall{
constructor(x1,x2,y1,y2){
this.a = createVector(x1,x2);
this.b = createVector(x2,y2);
}
show(){
stroke(255);
line(this.a.x, this.a.y, this.b.x, this.b.y);
}
}
我已经在index.HTML中放入了“ Wall.js”:
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>p5.js </title>
<style> body {padding: 0; margin: 0;} </style>
<script src="../p5.js"></script>
<script src="sketch.js"></script>
<script src="Wall.js"></script>
</head>
<body>
</body>
</html>
那可能是什么问题?