JavaScript doesn't have classes or type hinting. You can do something like:
var Vector3 = function(x, y, z) {
this.x = x;
this.y = y;
this.z = z;
}
var dotProduct = function(a, b) {
// do something with a.x, a.y, a.z, b.x, b.y, b.z
return new Vector3(...);
}
To create a new Vector3, you can use the new keyword:
// x y z
var v1 = new Vector3(1, 2, 3);
var v2 = new Vector3(2, 3, 4);
var product = dotProduct(v1, v2);
You can also add the dotProduct() function on Vector3 instances:
Vector3.prototype.dotProduct = function(b) {
// do something with this.x, this.y, this.z, b.x, b.y, b.z
return new Vector3(...);
}
in which case you could call it as:
var v1 = new Vector3(1, 2, 3);
var v2 = new Vector3(2, 3, 4);
var product = v1.dotProduct(v2);
To make your intention clear, you can add type hinting in comments:
/**
* @param Number x
* @param Number y
* @param Number z
* @constructor
*/
var Vector3 = function(x, y, z) {
this.x = x;
this.y = y;
this.z = z;
}
/**
* @param Vector3 b
* @return Vector3
*/
Vector3.prototype.dotProduct = function(b) {
// do something with this.x, this.y, this.z, b.x, b.y, b.z
return new Vector3(...);
}
Most JavaScript IDEs will know what that means and will help you by emitting warnings when you don't pass Vector3s as arguments.