JSFiddle - React, Tailwind, and code Playground

by toby3105

JavaScript

var Point = function (x, y, callback) {
    this.x = x;
    this.y = y;
    this.callback = callback;
};

Point.prototype = function () {
    var X = function (value) {
        if (value) {
            this.x = value;
            console.log(this);
            callCallback.call(this, "X changed");
        } else {
            return this.x;
        }
    };
    var Y = function (value) {
        if (value) {
            this.y = value;
            console.log(this);
            callCallback.call(this, "Y changed");
        } else {
            return this.y;
        }
    },
    callCallback = function (message) {
        console.log(this);
        if (this.callback) {
            callback(message)
        }
    }
    return {
        X: X,
        Y: Y
    };
}();

function callback(message) {
    console.log(message);
}
var p = new Point(10, 20, callback);
console.log(p.X());
p.X(321);
console.log(p.X());
console.log(p.Y());