Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

[[Define]] semantics necessitate workarounds #322

@trusktr

Description

@trusktr

I had code like the following, which worked great with [[Set]] semantics (f.e. in TypeScript with useDefineForClassFields set to false):

class Sub extends Node {...}
const s = new Sub({prop1: 1, prop2: 2})
class Sub2 extends Sub {...}
const s2 = new Sub2({prop1: 1, prop2: 2, prop3: 3})

but due to [[Define]] semantics, I had to change it to

class Sub extends Node {...}
const s = new Sub().set({prop1: 1, prop2: 2})
class Sub2 extends Sub {...}
const s2 = new Sub2().set({prop1: 1, prop2: 2, prop3: 3})

because of [[Define]]'s accessor-overriding nature.

I like the new set() API better (because it duals as an API for setting properties at any time and via constructor, not just via constructor), but the main point is I was forced to make this change, whereas otherwise I could've opted into making this API later (and it would work regardless of [[Set]] vs [[Define]]) and avoided making a breaking change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions