SlideShare a Scribd company logo
Daniel Ostrovsky
Falling in Love With Decorators
PROFESSIONAL JS CONFERENCE
8-9 NOVEMBER ‘19 KYIV, UKRAINE
2
Falling in Love With Decorators.
By Daniel Ostrovsky Web Team Lead at Kaltura
@danduh81
@danduh
3
• What decorators is?
• When do we need it and when not.
• Property decorators
• Method decorators
• Class decorators
• Arguments decorators (TS)
• And many more…
Subject
4
What decorators is?
Design pattern.
One of the twenty-three well-known GoF design patterns.
Extend the functionality of classes and methods in a clean
and declarative fashion.
5
Disclaimer
Decorators are currently at
Stage II
as part of
TC39's process.
Angular, Nest.Js,
Stencil, MobX,
core-decorators, ember-decorators,
lodash-decorators
6
Proposal
Yehuda Katz
2015
7
Proposal
HEY!!!
You GOT a Wrong Guy!!!
8
Proposal
Yehuda Katz
GitHub: wycats
https://yehudakatz.com/
9
Proposal
A decorator is:
• an expression
• that evaluates to a function
• that takes the target, name, and property descriptor as arguments
• and optionally returns a property descriptor to install on the target object
https://github.com/tc39/proposal-decorators
10
Common Use Cases
• Functional
o Helpers
o Logger
o Performance measuring
• Web Worker runner
• Validators
• Class mixing/composite
• Code analysing
• Memoization
• Access control and authentication
• **Additional functionality
• And many more…
11
Descriptor
let todoObj = {
summary: 'Write article about descriptors',
assigned: 'me',
deadLine: 1602280800
};
let descriptor = Object.getOwnPropertyDescriptor(todoObj, 'deadLine');
console.log(descriptor);
// Output:
{
value: 1602280800,
writable: true,
enumerable: true,
configurable: true
}
12
Descriptor // Output:
{
value: 1602280800,
writable: true,
enumerable: true,
configurable: true
}
• “value” - actual property value
• “writable” - is value of this property can be changed
• “enumerable” - is this property is enterable, is it can be used
in
• for (let key of todoObj) {} / Object.keys(todoObj)
• “configurable” - is entire descriptor can be changed
● The way we can call higher-order function.
● Function that takes another functions, extends its behaviour (without
modifying it) and returns it.
● “@” indicator for parser, that we using decorator.
● “readOnly” - name of our higher-order function.
Class member @Decorator (methods/properties)
13
export function readOnly(target, key, descriptor) {
descriptor.writable = false;
return descriptor;
}
class TodoObject{
@readOnly
timeLeft(){}
}
● target - class - TodoObject
● key - decorated method/property name - “timeLeft”
● descriptor - descriptor object of decorated method/property
Class member @Decorator (methods/properties)
14
export function readOnly(target, key, descriptor) {
descriptor.writable = false;
return descriptor;
}
class TodoObject{
@readOnly
timeLeft(){}
}
const descriptor = Object.getOwnPropertyDescriptor(TodoItem, 'timeLeft');
Краще один раз кодувати ніж тисячу разів,
слухати про те, як саме.
A coding is worth a thousand words….
• Class decorator accepts target (class) and returns
constructor.
• constructor - is nothing but a function which is used to add
prototype methods and define some initial values.
Class Decorators
THANK YOU!!!Articles
@danduh81

More Related Content

PDF
JavaScript Objects
PPTX
Type script
PPTX
Constructors
PPTX
[OOP - Lec 04,05] Basic Building Blocks of OOP
KEY
PPTX
[OOP - Lec 09,10,11] Class Members & their Accessing
PPTX
What is Constructors and Destructors in C++ (Explained with Example along wi...
PPTX
Object-oriented in ruby
JavaScript Objects
Type script
Constructors
[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 09,10,11] Class Members & their Accessing
What is Constructors and Destructors in C++ (Explained with Example along wi...
Object-oriented in ruby

Similar to JS Fest 2019/Autumn. Daniel Ostrovsky. Falling in love with decorators ES6/TypeScript (20)

PPTX
Decorators | TypeScript | Angular2 Decorators
PDF
Decorators in js
PDF
Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)
PDF
Decorators Lightning Talk for Triangle JavaScript
PPTX
Decorator Pattern presentation theory and examples
PPTX
Design pattern reading group – decorator pattern
PPTX
Decorator Pattern 2.pptxdsadsadsadsadasdasdsa
PPTX
Decorator Pattern
PPTX
ECMA5 approach to building JavaScript frameworks with Anzor Bashkhaz
PDF
Structure-Decorator deign pattern model fact
PPT
Stoop 439-decorator
PPTX
Python Decorators
PPT
Phani Kumar - Decorator Pattern
PPTX
java training in chennai
PPTX
Decorator Design Pattern
PPTX
Decorator design pattern
PPTX
Decorator design pattern
PDF
Decorator Pattern | Object Oriented Design Pattern
PPTX
Typescript Decorators
PDF
Advanced Python Techniques: Decorators
Decorators | TypeScript | Angular2 Decorators
Decorators in js
Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)
Decorators Lightning Talk for Triangle JavaScript
Decorator Pattern presentation theory and examples
Design pattern reading group – decorator pattern
Decorator Pattern 2.pptxdsadsadsadsadasdasdsa
Decorator Pattern
ECMA5 approach to building JavaScript frameworks with Anzor Bashkhaz
Structure-Decorator deign pattern model fact
Stoop 439-decorator
Python Decorators
Phani Kumar - Decorator Pattern
java training in chennai
Decorator Design Pattern
Decorator design pattern
Decorator design pattern
Decorator Pattern | Object Oriented Design Pattern
Typescript Decorators
Advanced Python Techniques: Decorators
Ad

More from JSFestUA (20)

PDF
JS Fest 2019/Autumn. Роман Савіцький. Webcomponents & lit-element in production
PDF
JS Fest 2019/Autumn. Erick Wendel. 10 secrets to improve Javascript Performance
PDF
JS Fest 2019/Autumn. Alexandre Gomes. Embrace the "react fatigue"
PDF
JS Fest 2019/Autumn. Anton Cherednikov. Choreographic or orchestral architect...
PDF
JS Fest 2019/Autumn. Adam Leos. So why do you need to know Algorithms and Dat...
PDF
JS Fest 2019/Autumn. Marko Letic. Saving the world with JavaScript: A Data Vi...
PPTX
JS Fest 2019/Autumn. Александр Товмач. JAMstack
PPTX
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
PPTX
JS Fest 2019/Autumn. Дмитрий Жарков. Blockchainize your SPA or Integrate Java...
PPTX
JS Fest 2019/Autumn. Maciej Treder. Angular Schematics - Develop for developers
PPTX
JS Fest 2019/Autumn. Kyle Boss. A Tinder Love Story: Create a Wordpress Blog ...
PPTX
JS Fest 2019/Autumn. Андрей Старовойт. Зачем нужен тип "true" в TypeScript?
PPTX
JS Fest 2019/Autumn. Eyal Eizenberg. Tipping the Scale
PDF
JS Fest 2019/Autumn. Sota Ohara. Сreate own server less CMS from scratch
PPTX
JS Fest 2019/Autumn. Джордж Евтушенко. Как стать программистом, которого хотят
PDF
JS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for Rust
PPTX
JS Fest 2019/Autumn. Андрей Андрийко. Гексагональна архітектура в Nodejs проекті
PPTX
JS Fest 2019/Autumn. Борис Могила. Svelte. Почему нам не нужно run-time ядро
PPTX
JS Fest 2019/Autumn. Виталий Кухар. Сравнение кластеризации HTTP, TCP и UDP н...
PDF
JS Fest 2019. Виктор Турский. 6 способов взломать твое JavaScript приложение
JS Fest 2019/Autumn. Роман Савіцький. Webcomponents & lit-element in production
JS Fest 2019/Autumn. Erick Wendel. 10 secrets to improve Javascript Performance
JS Fest 2019/Autumn. Alexandre Gomes. Embrace the "react fatigue"
JS Fest 2019/Autumn. Anton Cherednikov. Choreographic or orchestral architect...
JS Fest 2019/Autumn. Adam Leos. So why do you need to know Algorithms and Dat...
JS Fest 2019/Autumn. Marko Letic. Saving the world with JavaScript: A Data Vi...
JS Fest 2019/Autumn. Александр Товмач. JAMstack
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Дмитрий Жарков. Blockchainize your SPA or Integrate Java...
JS Fest 2019/Autumn. Maciej Treder. Angular Schematics - Develop for developers
JS Fest 2019/Autumn. Kyle Boss. A Tinder Love Story: Create a Wordpress Blog ...
JS Fest 2019/Autumn. Андрей Старовойт. Зачем нужен тип "true" в TypeScript?
JS Fest 2019/Autumn. Eyal Eizenberg. Tipping the Scale
JS Fest 2019/Autumn. Sota Ohara. Сreate own server less CMS from scratch
JS Fest 2019/Autumn. Джордж Евтушенко. Как стать программистом, которого хотят
JS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for Rust
JS Fest 2019/Autumn. Андрей Андрийко. Гексагональна архітектура в Nodejs проекті
JS Fest 2019/Autumn. Борис Могила. Svelte. Почему нам не нужно run-time ядро
JS Fest 2019/Autumn. Виталий Кухар. Сравнение кластеризации HTTP, TCP и UDP н...
JS Fest 2019. Виктор Турский. 6 способов взломать твое JavaScript приложение
Ad

Recently uploaded (20)

PDF
Anesthesia in Laparoscopic Surgery in India
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
master seminar digital applications in india
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Complications of Minimal Access Surgery at WLH
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Cell Types and Its function , kingdom of life
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Classroom Observation Tools for Teachers
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
RMMM.pdf make it easy to upload and study
Anesthesia in Laparoscopic Surgery in India
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Microbial disease of the cardiovascular and lymphatic systems
Supply Chain Operations Speaking Notes -ICLT Program
Abdominal Access Techniques with Prof. Dr. R K Mishra
master seminar digital applications in india
O7-L3 Supply Chain Operations - ICLT Program
Module 4: Burden of Disease Tutorial Slides S2 2025
Complications of Minimal Access Surgery at WLH
Basic Mud Logging Guide for educational purpose
Cell Types and Its function , kingdom of life
2.FourierTransform-ShortQuestionswithAnswers.pdf
TR - Agricultural Crops Production NC III.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Classroom Observation Tools for Teachers
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
RMMM.pdf make it easy to upload and study

JS Fest 2019/Autumn. Daniel Ostrovsky. Falling in love with decorators ES6/TypeScript

  • 1. Daniel Ostrovsky Falling in Love With Decorators PROFESSIONAL JS CONFERENCE 8-9 NOVEMBER ‘19 KYIV, UKRAINE
  • 2. 2 Falling in Love With Decorators. By Daniel Ostrovsky Web Team Lead at Kaltura @danduh81 @danduh
  • 3. 3 • What decorators is? • When do we need it and when not. • Property decorators • Method decorators • Class decorators • Arguments decorators (TS) • And many more… Subject
  • 4. 4 What decorators is? Design pattern. One of the twenty-three well-known GoF design patterns. Extend the functionality of classes and methods in a clean and declarative fashion.
  • 5. 5 Disclaimer Decorators are currently at Stage II as part of TC39's process. Angular, Nest.Js, Stencil, MobX, core-decorators, ember-decorators, lodash-decorators
  • 9. 9 Proposal A decorator is: • an expression • that evaluates to a function • that takes the target, name, and property descriptor as arguments • and optionally returns a property descriptor to install on the target object https://github.com/tc39/proposal-decorators
  • 10. 10 Common Use Cases • Functional o Helpers o Logger o Performance measuring • Web Worker runner • Validators • Class mixing/composite • Code analysing • Memoization • Access control and authentication • **Additional functionality • And many more…
  • 11. 11 Descriptor let todoObj = { summary: 'Write article about descriptors', assigned: 'me', deadLine: 1602280800 }; let descriptor = Object.getOwnPropertyDescriptor(todoObj, 'deadLine'); console.log(descriptor); // Output: { value: 1602280800, writable: true, enumerable: true, configurable: true }
  • 12. 12 Descriptor // Output: { value: 1602280800, writable: true, enumerable: true, configurable: true } • “value” - actual property value • “writable” - is value of this property can be changed • “enumerable” - is this property is enterable, is it can be used in • for (let key of todoObj) {} / Object.keys(todoObj) • “configurable” - is entire descriptor can be changed
  • 13. ● The way we can call higher-order function. ● Function that takes another functions, extends its behaviour (without modifying it) and returns it. ● “@” indicator for parser, that we using decorator. ● “readOnly” - name of our higher-order function. Class member @Decorator (methods/properties) 13 export function readOnly(target, key, descriptor) { descriptor.writable = false; return descriptor; } class TodoObject{ @readOnly timeLeft(){} }
  • 14. ● target - class - TodoObject ● key - decorated method/property name - “timeLeft” ● descriptor - descriptor object of decorated method/property Class member @Decorator (methods/properties) 14 export function readOnly(target, key, descriptor) { descriptor.writable = false; return descriptor; } class TodoObject{ @readOnly timeLeft(){} } const descriptor = Object.getOwnPropertyDescriptor(TodoItem, 'timeLeft');
  • 15. Краще один раз кодувати ніж тисячу разів, слухати про те, як саме. A coding is worth a thousand words….
  • 16. • Class decorator accepts target (class) and returns constructor. • constructor - is nothing but a function which is used to add prototype methods and define some initial values. Class Decorators