Decorator with (@) symbol in JS

PHOTO EMBED

Thu Apr 14 2022 09:04:51 GMT+0000 (Coordinated Universal Time)

Saved by @nebozoid #javascript

// decorator lights is a function which receives the class as an argument
let lights = function(tree) {
  // The behaviour of the class is modified here
  tree.treeLights = 'Christmas lights'
}

@lights  // the decorator is applied here
class ChristmasTree {}

console.log(ChristmasTree.treeLights);  // logs Christmas lights
content_copyCOPY

https://stackoverflow.com/questions/31821084/what-does-the-at-symbol-do-in-es6-javascript-ecmascript-2015