Open
Description
Js structs have a number of disadvantages:
- methods are unbound
- new construction
- This behaves weirdly.
- No explicit handling of
We could substitute our own syntax:
// Foo extends Bar
const Foo = struct('Foo', Bar, {
// property; must be set during initialization
'foo': undefined,
// property with default value (supplied using deep clone)
'foo': 42,
// property, with value generated by calling the function
'foo': Prop.init((self) => undefined),
// property; with getter/setter
'foo': Prop({
get: (self) =>,
set: (self) =>,
}),
// property;
// property, assigned by calling the provided function
// Bound method syntax
'foo': (self) => …
// Static bound method/property/etc
'@foo': (cls) => …
});
Only hard rule is: @
is for static, no @
is instance.
Provide some trait intoProp
or something that contains normalization rules for properties that turn everything into a Property({ init(), get(), set() })
. The normalization rule for undefined is to throw (to enforce explicit initialization). The normalization rule for Functions is binding on initialization and hiding from enumerable properties and so on.
By default .init(foo, bar, baz)
and .namedInit({ foo, bar, baz })
is provided.
Highly flexible; metaprogrammable; supports reflection.