Comments (2)
Initializers for class definitions initialize the class definition itself. Think of them like static fields or blocks, they run once on the class itself to fully initialize it.
To understand why this is necessary, vs just returning a new class definition, you can look at some of the older issues discussing this. A good example is defining web components based on a class. The component must be registered after static fields are assigned, due to the way the API works. However, static fields must be assigned after decorators have returned the new class definition, so they can use the finalized class definition in their initializers. So a step was needed after fields are assigned, thus the timing.
to run initialization code on class instantiation, extend the class and put the code in the constructor instead.
from proposal-decorators.
Got it, thanks for explanation.
from proposal-decorators.
Related Issues (20)
- Idea: syntax for decorator composition. HOT 3
- How to exclude methods from class decorator HOT 2
- Add target class to the context HOT 6
- Order of execution HOT 3
- feature request (separate proposal?): `context.addPostInitializer()` HOT 18
- Readme text and types are outdated against actual spec HOT 2
- Field decorator initializer should support configurable field HOT 8
- Was there a purpose for non-lexical ordering of decorator applications? HOT 2
- Write upgrade guide for previous iterations to Stage 3
- Clarification on field vs. method destination HOT 8
- Intercept class field get/set (without accessor on prototype) HOT 13
- Clarification. Can auto-accessors be redeclared? HOT 2
- change the `bound` example from this[name] = `this[name].bind(this)` to `this[name] = target.bind(this)` for supporting Private properties
- Metadata inheritance HOT 2
- Can I run private fields in the decorator? HOT 1
- auto-accessors: difference between `value.get` and `context.access.get` HOT 7
- Should auto-accessors `value.set` return `void` or the value? HOT 2
- Error in example
- Auto-Accessors behavior within the super.constructor body HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proposal-decorators.