JSFiddle - React, Tailwind, and code Playground

by amatiasq

JavaScript

// Constructor
function Vector(x, y) {
    this.x = x;
    this.y = y;
}
Vector.prototype.isZero = function() {
    return this.x === 0 && this.y === 0;
};
Vector.prototype.merge = function(vector) {
    this.x += vector.x;
    this.y += vector.y;
};
Vector.prototype.toString = function() {
    return '[Vector{' + this.x + ',' + this.y + ']';
};

// Object
var Vector = {
    constructor: function(x, y) {
        this.x = x;
        this.y = y;
    },
    isZero = function() {
        return this.x === 0 && this.y === 0;
    },
    merge = function(vector) {
        this.x += vector.x;
        this.y += vector.y;
    },
    toString = function() {
        return '[Vector{' + this.x + ',' + this.y + ']';
    }
};