mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
Add structural comparison
This commit is contained in:
@@ -11,6 +11,7 @@ export const orderedFiles = [
|
||||
"/tutorial/revertOnCatch.ts",
|
||||
"/tutorial/strings.ts",
|
||||
"/tutorial/const.ts",
|
||||
"/tutorial/structuralComparison.ts",
|
||||
"/tutorial/binaryTree.ts",
|
||||
"/tutorial/specialFunctions.ts",
|
||||
"/tutorial/treeShaking.ts",
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Also due to value semantics, arrays and objects are compared on their content instead of their
|
||||
// identity.
|
||||
|
||||
export default function () {
|
||||
return vec3(-5, 7, 12) === vec3(-5, 7, 12);
|
||||
// JavaScript: false
|
||||
// ValueScript: true
|
||||
}
|
||||
|
||||
function vec3(x: number, y: number, z: number) {
|
||||
return { x, y, z };
|
||||
}
|
||||
|
||||
// Caveat:
|
||||
// - TypeScript will emit an error for expressions like `[a, b] === [c, d]`.
|
||||
//
|
||||
// This is unfortunate. It's to protect you from accidentally expecting structural comparison in JS,
|
||||
// but in ValueScript, that's exactly how it *does* work.
|
||||
//
|
||||
// ValueScript will still happily evaluate these expressions (ValueScript doesn't use the TS
|
||||
// compiler), but you might want to rewrite these expressions as `eq([a, b], [c, d])` until
|
||||
// dedicated ValueScript intellisense is available.
|
||||
Reference in New Issue
Block a user