Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 203f693

Browse files
committed
add oop_javascript
1 parent 357c8ea commit 203f693

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function Vector(var _x, var _y){
2+
this.x = _x;
3+
this.y = _y;
4+
}
5+
6+
Vector.prototype.plus = function(vector){
7+
return new Vector(this.x + vector.x, this.y + vector.y);
8+
}
9+
10+
Vector.prototype.minus = function(vector){
11+
return new Vector(this.x - vector.x, this.y - vector.y);
12+
}
13+
14+
// Test
15+
console.log(new Vector(1, 2).plus(new Vector(2, 3)));
16+
// => Vector{x: 3, y: 5}
17+
console.log(new Vector(1, 2).minus(new Vector(2, 3)));
18+
// => Vector{x: -1, y: -1}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /