Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add decorator support to defclass #493

Open
seanstrom opened this issue Mar 28, 2024 · 0 comments
Open

Add decorator support to defclass #493

seanstrom opened this issue Mar 28, 2024 · 0 comments

Comments

@seanstrom
Copy link

Summary

  • It could be nice to support decorator functions with the defclass syntax for fields, methods and classes.
  • Ideally, there would be some way to interop with JS decorator functions with the defclass syntax.
  • Note, it seems that decorators can be implemented in a variety of ways, and I'm not sure if there's a best way to standardise support, so more research may be required.

What are decorators?

How are Decorators used in JavaScript?

Decorators are functions that can modify the definition of class (and more) in JS, for example:

function decoratorName(opts) {
  return (target, key, descriptor) => {
    return descriptor
  }
}

class Example extends Foo {
  @decoratorName
  fieldName
}

Would be roughly de-sugared into:

let fieldDescriptor = Object.getOwnPropertyDescriptor(Example.prototype, "fieldName")

let propertyConfig = decoratorName(undefined)(Example.prototype, "fieldName", fieldDescriptor) 

Object.defineProperty(Example.prototype, "fieldName", propertyConfig)
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant