mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-02 00:25:34 +08:00
- Run published three.js vector, matrix, and quaternion operations natively and as Wasm without a JavaScript engine. - Preserve shared class prototype data and JavaScript overload arguments. - Support Math function values and distinct npm import and require entries.
16 lines
607 B
JavaScript
16 lines
607 B
JavaScript
class Point {
|
|
static { Point.prototype.isPoint = true; }
|
|
constructor(x = 0) { this.x = x; }
|
|
}
|
|
/** @param {number} [value] */
|
|
function scalar(value) { return value === undefined ? 'missing' : value.toString(); }
|
|
/** @param {number|Point} value */
|
|
function coordinate(value) {
|
|
if (value.isPoint) return scalar(value.x);
|
|
return scalar(value);
|
|
}
|
|
console.log(coordinate(7), coordinate(new Point(9)), coordinate(0));
|
|
/** @param {number|Point|undefined} value */
|
|
function optionalBrand(value) { return value?.isPoint; }
|
|
console.log(optionalBrand(undefined), optionalBrand(2), optionalBrand(new Point(3)));
|