-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
Given the following case's class structure:
// addMetadata doesn't do anything, I just want the @@metadata added
@addMetadata
class SuperClass {}
// Notice SubClass doesn't have a decorator, so it doesn't have @@metadata
class SubClass extends SuperClass {}Because of the conditional semantics, the SubClass will not have the @@metadata object. And because the subclass's constructor's __proto__ will be set to SuperClass, accessing SubClass[@@metadata] will actually return SuperClass[@@metadata].
This can cause some potential bugs if the metadata of the class is mutated after the fact:
function doWorkWithMetadata(klass) {
const metadata = klass[Symbol.metadata];
if (metadata.__workDone) return;
// do some work on metadata
console.log(klass);
metadata.__workDone = true;
}
doWorkWithMetadata(SubClass);
doWorkWithMetadata(SuperClass);This will only "do work" on the subclass. Because the mutation will affect both the subclass and superclass, the superclass is skipped.
hax and tanhuy998
Metadata
Metadata
Assignees
Labels
No labels