Skip to content
This repository has been archived by the owner on Mar 12, 2023. It is now read-only.

implement objects example #26

Open
aczwink opened this issue Jan 23, 2022 · 3 comments
Open

implement objects example #26

aczwink opened this issue Jan 23, 2022 · 3 comments

Comments

@aczwink
Copy link
Owner

aczwink commented Jan 23, 2022

No description provided.

@aczwink aczwink self-assigned this Feb 6, 2022
@aczwink
Copy link
Owner Author

aczwink commented Feb 11, 2022

@aczwink aczwink removed their assignment Mar 23, 2022
@aczwink
Copy link
Owner Author

aczwink commented Jul 8, 2022

how javascript (and ts) do it:

typescript:

var glob = 0;

class Vec
{
	constructor(x: number, y: number)
	{
		this.x = x;
		this.y = y;
		
		if(glob == 1)
			return;
		glob = 1;
		
		const a = this.scale(3);
		this.x = a.x;
		this.y = a.y;
	}
	
	public scale(s: number)
	{
		return new Vec(this.x*s, this.y*s);
	}
	
	private x: number;
	private y: number;
}

const x = new Vec(3, 5);
console.log(x);
const y = new Vec(3, 5);
console.log(y);

javascript:

var glob = 0;
var Vec = /** @class */ (function () {
    function Vec(x, y) {
        this.x = x;
        this.y = y;
        if (glob == 1)
            return;
        glob = 1;
        var a = this.scale(3);
        this.x = a.x;
        this.y = a.y;
    }
    Vec.prototype.scale = function (s) {
        return new Vec(this.x * s, this.y * s);
    };
    return Vec;
}());
var x = new Vec(3, 5);
console.log(x);
var y = new Vec(3, 5);
console.log(y);

@aczwink
Copy link
Owner Author

aczwink commented Jul 8, 2022

prints Vec { x: 9, y: 15 } Vec { x: 3, y: 5 }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant