JavaScript simple class Vector

Simple class Vector, from here you can add function to the class as much as you need, here you can prototype it.


function Vector(X, Y) {
this.x = x || 0;
this.y = y || 0;
}

Example of prototype:

Vector.prototype.add = function(vector) {
this.x += vector.x;
this.y += vector.y;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s