Skip to content

Instantly share code, notes, and snippets.

@jhohlfeld
Created August 19, 2014 13:11
Show Gist options
  • Save jhohlfeld/4faa6aa6fbc2316c2805 to your computer and use it in GitHub Desktop.
Save jhohlfeld/4faa6aa6fbc2316c2805 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
var Vector = function(x, y) {
this.x = x;
this.y = y;
this.length = Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2));
};
Vector.prototype.plus = function (vector) {
return new Vector(this.x+vector.x, this.y+vector.y);
};
Vector.prototype.minus = function (vector) {
return new Vector(this.x-vector.x, this.y-vector.y);
};
</script>
</body>
</html>
var Vector = function(x, y) {
this.x = x;
this.y = y;
this.length = Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2));
};
Vector.prototype.plus = function (vector) {
return new Vector(this.x+vector.x, this.y+vector.y);
};
Vector.prototype.minus = function (vector) {
return new Vector(this.x-vector.x, this.y-vector.y);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment