我在 JavaScript 中有一些代码可以存储一些浮点数,但我似乎无法让它打印出正确的数据,这是我的代码片段,这是我遇到的问题。
function Vector3(x,y,z){
this.x = x; this.y = y; this.z = z;
}
function Edge(vec1, vec2){
var vector1 = new Vector3(vec1.x,vec1.y,vec1.z);
document.write(vector1.x+ "," +vector1.y +"," + vector1.z+"<br>");
var vector2 = new Vector3(vec2.x,vec2.y,vec2.z);
}
var sqrVer = new Array();
sqrVer[1] = new Vector3(-1.0, 1.0, 1.0);
sqrVer[2] = new Vector3( 1.0, 1.0, 1.0);
sqrVer[3] = new Vector3(-1.0, -1.0, 1.0);
sqrVer[4] = new Vector3( 1.0, -1.0, 1.0);
sqrVer[5] = new Vector3( 1.0, -1.0, -1.0);
sqrVer[6] = new Vector3( 1.0, 1.0, -1.0);
sqrVer[7] = new Vector3(-1.0, 1.0, -1.0);
sqrVer[8] = new Vector3(-1.0, -1.0, -1.0);
var sqrEdge = new Array();
sqrEdge[1] = new Edge(sqrVer[1], sqrVer[2]);
document.write(sqrVer[1].x + "<br>");
document.write(sqrEdge[1].vector1.x + "<br>");
现在打印出来的是这个
-1.0, 1.0, 1.0,
-1.0
但是对于到 sqrEdge 并尝试打印出 x 的行,没有任何内容写入屏幕???为什么是这样?