Skip to content

Navigation Menu

Sign in
Sign up
This repository was archived by the owner on Feb 28, 2018. It is now read-only.

Classes

Nidin Vinayakan edited this page Mar 15, 2017 · 2 revisions

Introduction 🚧

In object-oriented programming, a class is an extensible program-code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods).

Let’s take a look at a simple class-based example:

class Vec3 {
 x: float32;
 y: float32;
 z: float32;
 
 constructor(x: float32, y: float32, z: float32): Vec3 {
 this.x = x;
 this.y = y;
 this.z = z;
 return this;
 }
 
 add(b: Vec3): Vec3 {
 return new Vec3(this.x + b.x, this.y + b.y, this.z + b.z);
 }
}
export function newVec3(x: float32, y: float32, z: float32): Vec3 {
 return new Vec3(x, y, z);
}
export function addVec3(a:Vec3, b:Vec3): Vec3 {
 return a.add(b);
}
export function destroyVec3(a:Vec3): void {
 delete a;
}

Clone this wiki locally

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