Why decorators should be available everywhere

Adam Crockett 🌀 - Jul 13 '19 - - Dev Community

Please show your support! https://github.com/tc39/proposal-decorators/issues/119

Let's dive in, I believe this sample will explain better than words.

class SimpleRouter {
   @get '/home'
   ({ res }) {
      return res.html();
   }

   @post 'submit/myform'
   ({ somePlugin, res }) {
      somePlugin.handleData(res.data);
   }
}
Enter fullscreen mode Exit fullscreen mode

ps. what do you think about that slightly hacky syntax, cool huh?

But why can't this just be an object with decorators, I am forced to use a singleton for no good reason.

So people say you don't need classes but I'm afraid that syntactic sugar just keeps getting sweater.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player