You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 3, 2025. It is now read-only.
if an operator is prefixed or suffixed with a dot, it's interpreted as method invocation:
In form of a .op b, equivalent to a[Symbol.op](b)
In form of a op. b, equivalent to b[Symbol.op](a).
In form of a .op or .op a where op is an unary operator so that a op is currently-allowing syntax, equivalent to a[Symbol.op]()
In any of the forms, if the operand could not provide the corresponding method, let it fail as if the invocation has no method.
Examples
Given
De-sugar To
a .* b
a[Symbol.asterisk](b, true/* left */)
a *.b
b[Symbol.asterisk](a, false/* left */)
a .=== b
a[Symbol.strictEquals](b, true/* left */)
a !==. b
b[Symbol.notStrictEquals](a, false/* left */)
!.a
a[Symbol.exclaimaion]()
++.a
a[Symbol.plusPlus](true/* isPrefix */)
a.--
a[Symbol.minusMinus](false/* isPrefix */)
interfaceVec3{normalize(): Vec3;[Symbol.add](other: Vec3): Vec3;[Symbol.asterisk](other: Vec3|number): Vec3;}functionzoom(origin: Vec3,dir: Vec3,length: number){returnorigin.+(dir.normalize().*length);}console.log((1).+1);// Exception: 1[Symbol.add] is not a function
Props and Cons
Props
Almost zero-overhead, no runtime check.
Static, can be type-checked.
Does not affect current codebases.
Cons
Let me know.
FrameMuse, GregStanton, nakasyou and AlbertMarashi