Object0.25.1
expand_more
abstract external class Object extends Any
- Known subtypes:
- AlsoKnownAs, Annotation, AppEnvCluster, Benchmark, Benchmark, BenchmarkReport, BenchmarkResult, CData, Checksums, Class, Comment, CpuInput, CsvInputDataFormat, Declaration, DeclaredType, Deprecated, DiscardOutput, DiskInput, DocExample, DocPackageInfo, DocsiteInfo, Documentation, Dynamic, Editor, EvaluatorSettings, ExecInput, ExtVar, Field, FileInput, FileOutput, FileOutput, FunctionType, Generator, GeneratorSettings, HttpInput, IPv4Address, IPv4Network, IPv6Address, IPv6Network, ImportStr, Inline, Input, InputDataFormat, JsonInputDataFormat, JsonOutputDataFormat, JsonRenderer, JsonStructTag, Language, Listing, Mapping, Method, MethodParameter, Microbenchmark, Module, Module, ModuleInfo, ModuleOutput, ModuleType, Name, NetInput, NothingType, NullableType, OpenTelemetry, OperatingSystem, Output, OutputBenchmark, OutputDataFormat, PListRenderer, Package, Package, PackageDependency, Parser, Parser, ParserBenchmark, PcfRenderDirective, PcfRenderer, Platform, Plugin, Processor, Processor, Project, PrometheusClientOutput, PrometheusInput, PropertiesRenderer, Property, Regex, RegexMatch, Release, RemoteDependency, RenderDirective, Renderer, Renderer, Renderer, Resource, Runtime, Since, SocketListenerInput, SourceCode, SourceCode, SourceLocation, StandardLibrary, StarlarkProcessor, StringLiteralType, TailInput, Type, TypeAlias, TypeDeclaration, TypeParameter, TypeVariable, Typed, UInt128, UnionType, UnknownType, Unlisted, ValueRenderer, VarArgs, Version, VirtualMachine, YamlRenderer, base, convert, go, json, jsonnet, math, net, platform, protobuf, reflect, release, semver, settings, shell, test, u128, xml, yaml
- Known usages:
- All versions:
- 0.29.0-dev, 0.28.1, 0.28.0, 0.28.0-dev, 0.27.2, 0.27.1, 0.27.0, 0.26.3, 0.26.2, 0.26.1, 0.26.0, 0.25.3, 0.25.2, 0.25.1, 0.25.0-dev
obj = new {
name = "Pigeon" // property
"Hello" // element
["two"] = 2 // entry
}
obj.name // "Pigeon"
obj[0] // "Hello"
obj["two"] // 2
An object can be amended to create variants of itself. This is similar to inheritance in prototype-oriented programming.
pigeon = new { name = "Pigeon"; age = 42 }
barnOwl = (pigeon) { name = "Barn Owl" } // override property `name`
oldPigeon = (pigeon) { age = 84 } // override property `age`
Object members may reference other members:
thresholds = new { lower = 10; upper = lower + 5 }
Object members are dynamically bound. This is similar to how computed cells in a spreadsheet work.
thresholds = new { lower = 10; upper = lower + 5 }
thresholds2 = new { lower = 7 } // thresholds2.upper == 12
Objects have memberwise equality and hash code.
To arbitrarily manipulate an object, convert it to a Collection
.
If necessary, the manipulated Collection
can be converted back to an Object
.
pigeon = new { name = "Pigeon"; age = 42 }
manipulated = pigeon.toMap().mapKeys((key, value) -> key.reverse())
manipulated.toDynamic() // new { eman = "Pigeon"; ega = 42 }
A composite value containing members (properties, elements, entries).