SlideShare a Scribd company logo
Metaprogramming in
JavaScript
Web Directions Summit | November 17
Hello!
I am Mehdi Valikhani
Software Engineer at Autopilot
Metaprogramming?!
“Metaprogramming is a programming technique in
which computer programs have the ability to treat
programs as their data. It means that a program can
be designed to read, generate, analyse or transform
other programs or itself while running
source: Wikipedia
“Metaprogramming is a programming technique in
which computer programs have the ability to treat
programs as their data. It means that a program can
be designed to read, generate, analyse or transform
other programs or itself while running
source: Wikipedia
Reflection
“In computer science,reflection is the ability of a
computer program to examine,introspect, and modify
its own structure and behaviour at runtime. Reflection
is a valuable language feature and it facilitates
metaprogramming.
source: Wikipedia
Language features that enables
reflection
1.
Evaluate a string as if it
were a source code
statement at runtime.
2.
Convert a string matching
the symbolic name of a class
or function into a reference
to or invocation of that class
or function.
3.
Discover and modify source
code constructions (such as
code blocks, classes,
methods, protocols, etc.) as
first-class objects at
runtime.
source: Wikipedia
Reflective JavaScript
Metaprogramming
Reflective
JavaScript
Metaprogramming
Using ES5 features
Metaprogramming features of ES5
Code Evaluation
eval()
Examination
➔ instanceof
➔ typeof
➔ Object.getOwnPropertyNames()
Modification
Getter, setter
Reflective
JavaScript
Metaprogramming
Using ES6 features
Symbol ReflectProxy
Symbols
The new type in JavaScript
➔ The seventh type of values in JavaScript
Symbol
➔ The Symbol() function returns a value of type symbol
➔ Symbol() always returns unique values
➔ They may be used as an identifier for object properties
source: MDN
Example: Using Symbol as property identifier
const nameField = Symbol('beer name');
const beer = {
[nameField]: 'VB!'
};
console.log(beer[nameField]); // -> VB!
Example: Using Symbol as property identifier
const nameField = Symbol('beer name');
const beer = {
[nameField]: 'VB!'
};
console.log(beer[nameField]); // -> VB!
Example: Using Symbol as property identifier
const nameField = Symbol('beer name');
const beer = {
[nameField]: 'VB!'
};
console.log(beer[nameField]); // -> VB!
Example: Using Symbol as property identifier
const nameField = Symbol('beer name');
const beer = {
[nameField]: 'VB!'
};
console.log(beer[nameField]); // -> VB!
Well-known
Symbols
➔ A set of built-in JavaScript symbols
➔ Represent internal language behaviours
➔ They were not exposed to developers before
source: MDN
Symbols are used by ES6 to enable
“Reflection within implementation”.
Developers include them on their existing
classes and objects to change the default
behaviour of an operation or action.
source: keithcirkel.co.uk
What can be done using well-known symbols
➔ Control the behaviour of instanceof for an implemented class
➔ Manipulate the behaviour of for of when iterated over a class
➔ Control over Array.concat
➔ Custom matches for String.match(), String.replace(),
String.search() and String.split()
➔ Control the behaviour of Javascript when converting objects
to primitive types
Check MDN for a list of well-known symbols
Example: Using well-known Symbol.hasInstance to modify behaviour of “instanceof”
class MyArray {
}
const friends = ['foo', 'bar'];
console.log(friends instanceof MyArray); // -> false
class MyArray {
static [Symbol.hasInstance](object) {
return Array.isArray(object);
}
}
const friends = ['foo', 'bar'];
console.log(friends instanceof MyArray); // -> true
Example: Using well-known Symbol.toPrimitive for a ShoppingBasket class
class ShoppingBasket {
constructor() {
this.items = [];
}
add(title, quantity, price) {
this.items.push({ title, quantity, price});
}
total() {
return this.items.reduce(function(accumulator, item) {
return accumulator + (item.price * item.quantity);
}, 0);
}
}
}
const basket = new ShoppingBasket();
basket.add('bread', 2, 2.5);
basket.add('milk', 1, 1.4);
Example: Using well-known Symbol.toPrimitive for a ShoppingBasket class
class ShoppingBasket {
constructor() {
this.items = [];
}
add(title, quantity, price) {
this.items.push({ title, quantity, price});
}
total() {
return this.items.reduce(function(accumulator, item) {
return accumulator + (item.price * item.quantity);
}, 0);
}
[Symbol.toPrimitive](hint) {
if (hint === 'number') return this.total();
return this;
}
}
const basket = new ShoppingBasket();
basket.add('bread', 2, 2.5);
basket.add('milk', 1, 1.4);
console.log(+basket); // -> 6.4
console.log(new Number(basket)); // -> 6.4
Example: Using well-known Symbol.toPrimitive for a ShoppingBasket class
class ShoppingBasket {
constructor() {
this.items = [];
}
add(title, quantity, price) {
this.items.push({ title, quantity, price});
}
total() {
return this.items.reduce(function(accumulator, item) {
return accumulator + (item.price * item.quantity);
}, 0);
}
[Symbol.toPrimitive](hint) {
if (hint === 'number') return this.total();
return this;
}
}
const basket = new ShoppingBasket();
basket.add('bread', 2, 2.5);
basket.add('milk', 1, 1.4);
console.log(+basket); // -> 6.4
console.log(new Number(basket)); // -> 6.4
Proxy
Proxy, as the name indicates, provides
“Reflection through interception”.
It wraps objects and intercepts their
behaviours through traps.
source: keithcirkel.co.uk
What can be done using Proxy
➔ A trap for delete operator
➔ Manipulate the behaviour of in operator
➔ Control over getting and setting property values
➔ A trap for function calls
➔ A trap for new operator
Check MDN for a list of Proxy features
Example: Implementation of a virtual field using Proxy
const student = {
firstName: 'Jackson',
lastName: 'Rowe',
};
const studentProxy = {
get: function(object, fieldName) {
if (fieldName === 'fullName') {
return `${object.firstName} ${object.lastName}`;
}
return object[fieldName];
}
};
const proxiedStudent = new Proxy(student, studentProxy);
console.log(proxiedStudent.fullName); // -> Jackson Rowe
Example: Implementation of a virtual field using Proxy
const student = {
firstName: 'Jackson',
lastName: 'Rowe',
};
const studentProxy = {
get: function(object, fieldName) {
if (fieldName === 'fullName') {
return `${object.firstName} ${object.lastName}`;
}
return object[fieldName];
}
};
const proxiedStudent = new Proxy(student, studentProxy);
console.log(proxiedStudent.fullName); // -> Jackson Rowe
Example: Implementation of a virtual field using Proxy
const student = {
firstName: 'Jackson',
lastName: 'Rowe',
};
const studentProxy = {
get: function(object, fieldName) {
if (fieldName === 'fullName') {
return `${object.firstName} ${object.lastName}`;
}
return object[fieldName];
}
};
const proxiedStudent = new Proxy(student, studentProxy);
console.log(proxiedStudent.fullName); // -> Jackson Rowe
Example: Implementation of a virtual field using Proxy
const student = {
firstName: 'Jackson',
lastName: 'Rowe',
};
const studentProxy = {
get: function(object, fieldName) {
if (fieldName === 'fullName') {
return `${object.firstName} ${object.lastName}`;
}
return object[fieldName];
}
};
const proxiedStudent = new Proxy(student, studentProxy);
console.log(proxiedStudent.fullName); // -> Jackson Rowe
Example: Value validation using Proxy
const student = {
firstName: 'Jackson',
lastName: 'Rowe',
};
const studentProxy = {
set: function(object, fieldName, value) {
// validation logic for the “age” field
if (fieldName === 'age') {
if (typeof value !== 'number') {
throw TypeError('only numbers are accepted');
}
if (value <= 0) throw TypeError('that is impossible');
}
object[fieldName] = value;
return true;
}
};
const proxiedStudent = new Proxy(student, studentProxy);
proxiedStudent.age = 'a'; // errors
proxiedStudent.age = -1; // errors
proxiedStudent.age = 12; // does not error
Example: Value validation using Proxy
const student = {
firstName: 'Jackson',
lastName: 'Rowe',
};
const studentProxy = {
set: function(object, fieldName, value) {
// validation logic for the “age” field
if (fieldName === 'age') {
if (typeof value !== 'number') {
throw TypeError('only numbers are accepted');
}
if (value <= 0) throw TypeError('that is impossible');
}
object[fieldName] = value;
return true;
}
};
const proxiedStudent = new Proxy(student, studentProxy);
proxiedStudent.age = 'a'; // errors
proxiedStudent.age = -1; // errors
proxiedStudent.age = 12; // does not error
Example: Value validation using Proxy
const student = {
firstName: 'Jackson',
lastName: 'Rowe',
};
const studentProxy = {
set: function(object, fieldName, value) {
// validation logic for the “age” field
if (fieldName === 'age') {
if (typeof value !== 'number') {
throw TypeError('only numbers are accepted');
}
if (value <= 0) throw TypeError('that is impossible');
}
object[fieldName] = value;
return true;
}
};
const proxiedStudent = new Proxy(student, studentProxy);
proxiedStudent.age = 'a'; // errors
proxiedStudent.age = -1; // errors
proxiedStudent.age = 12; // does not error
Example: Value validation using Proxy
const student = {
firstName: 'Jackson',
lastName: 'Rowe',
};
const studentProxy = {
set: function(object, fieldName, value) {
// validation logic for the “age” field
if (fieldName === 'age') {
if (typeof value !== 'number') {
throw TypeError('only numbers are accepted');
}
if (value <= 0) throw TypeError('that is impossible');
}
object[fieldName] = value;
return true;
}
};
const proxiedStudent = new Proxy(student, studentProxy);
proxiedStudent.age = 'a'; // errors
proxiedStudent.age = -1; // errors
proxiedStudent.age = 12; // does not error
Example: Protect “id” field from deletion using a Proxy
const student = {
id: 'jackson-rowe',
firstName: 'Jackson',
lastName: 'Rowe',
};
const studentProxy = {
deleteProperty: function(object, fieldName) {
if (fieldName === 'id') return false;
delete object[fieldName];
return true;
}
};
const proxiedStudent = new Proxy(student, studentProxy);
delete proxiedStudent.id // -> false
console.log(proxiedStudent.id); // jackson-rowe
Example: Protect “id” field from deletion using a Proxy
const student = {
id: 'jackson-rowe',
firstName: 'Jackson',
lastName: 'Rowe',
};
const studentProxy = {
deleteProperty: function(object, fieldName) {
if (fieldName === 'id') return false;
delete object[fieldName];
return true;
}
};
const proxiedStudent = new Proxy(student, studentProxy);
delete proxiedStudent.id // -> false
console.log(proxiedStudent.id); // jackson-rowe
Example: Protect “id” field from deletion using a Proxy
const student = {
id: 'jackson-rowe',
firstName: 'Jackson',
lastName: 'Rowe',
};
const studentProxy = {
deleteProperty: function(object, fieldName) {
if (fieldName === 'id') return false;
delete object[fieldName];
return true;
}
};
const proxiedStudent = new Proxy(student, studentProxy);
delete proxiedStudent.id // -> false
console.log(proxiedStudent.id); // jackson-rowe
Example: Protect “id” field from deletion using a Proxy
const student = {
id: 'jackson-rowe',
firstName: 'Jackson',
lastName: 'Rowe',
};
const studentProxy = {
deleteProperty: function(object, fieldName) {
if (fieldName === 'id') return false;
delete object[fieldName];
return true;
}
};
const proxiedStudent = new Proxy(student, studentProxy);
delete proxiedStudent.id // -> false
console.log(proxiedStudent.id); // jackson-rowe
Reflect
JavaScript’s new built-in object
Reflect is all about “Reflection through
introspection” - provides API to discover very
low level information about code.
source: keithcirkel.co.uk
What can be done using Reflect
➔ Call a function using Reflect.apply()
➔ Define a property using Reflect.defineProperty()
➔ Delete a property using Control over Reflect.deleteProperty()
➔ Get a property value using Reflect.get()
➔ Set property value using Reflect.set()
➔ Check if a property exist using Reflect.has()
Check MDN for a list of Reflect features
What Reflect object offers are either a
newer versions of existing methods or
entirely new methods - allowing new levels
of Reflection within JavaScript.
source: keithcirkel.co.uk
Example: Deleting a property using Reflect.deleteProperty()
const student = {
firstName: 'Jackson',
lastName: 'Rowe',
};
console.log(student.firstName); // -> Jackson
Reflect.deleteProperty(student, 'firstName');
console.log(student.firstName); // -> undefined
Example: Deleting a property using Reflect.deleteProperty()
const student = {
firstName: 'Jackson',
lastName: 'Rowe',
};
console.log(student.firstName); // -> Jackson
Reflect.deleteProperty(student, 'firstName');
console.log(student.firstName); // -> undefined
Example: Deleting a property using Reflect.deleteProperty()
const student = {
firstName: 'Jackson',
lastName: 'Rowe',
};
console.log(student.firstName); // -> Jackson
Reflect.deleteProperty(student, 'firstName');
console.log(student.firstName); // -> undefined
Example: Deleting a property using Reflect.deleteProperty()
const student = {
firstName: 'Jackson',
lastName: 'Rowe',
};
console.log(student.firstName); // -> Jackson
Reflect.deleteProperty(student, 'firstName');
console.log(student.firstName); // -> undefined
100%Modern Browsers (Edge, Firefox, Safari, Chrome)
0%IE 11
100%Node 8
source: http://kangax.github.io/compat-table/es6/
Native support
Resources
● Wikipedia - Metaprogramming
● Wikipedia - Reflection in Computer Science
● Mozilla - Metaprogramming
● Metaprogramming in ES6 by Keith Cirkel
Credits
Special thanks to all the people who made and
released these awesome resources for free:
▷ MDN web docs
▷ Wikipedia and the contributors
▷ Keith Cirkel for the Metaprogramming series
▷ Presentation template by SlidesCarnival
Thanks!
Any questions?
You can find me at:
➔ @mehdivk
➔ linkedin.com/in/valikhani/
➔ hi@mv.id.au

More Related Content

What's hot (20)

Bottom Up
Bottom UpBottom Up
Bottom Up
Brian Moschel
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...
go_oh
 
Powerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best PracticesPowerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best Practices
Dragos Ionita
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testing
Vikas Thange
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
Ankit Rastogi
 
Java script
Java scriptJava script
Java script
vishal choudhary
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
Shlomi Komemi
 
JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101
ygv2000
 
JavaScript in Object-Oriented Way
JavaScript in Object-Oriented WayJavaScript in Object-Oriented Way
JavaScript in Object-Oriented Way
Chamnap Chhorn
 
A Re-Introduction to JavaScript
A Re-Introduction to JavaScriptA Re-Introduction to JavaScript
A Re-Introduction to JavaScript
Simon Willison
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript
Anjan Banda
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
Bala Narayanan
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
Walid Ashraf
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
Bui Kiet
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
Adieu
 
Object Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptObject Oriented Programming in JavaScript
Object Oriented Programming in JavaScript
zand3rs
 
Javascript tid-bits
Javascript tid-bitsJavascript tid-bits
Javascript tid-bits
David Atchley
 
Java script -23jan2015
Java script -23jan2015Java script -23jan2015
Java script -23jan2015
Sasidhar Kothuru
 
Object Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptObject Oriented Programming In JavaScript
Object Oriented Programming In JavaScript
Forziatech
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
Mats Bryntse
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...
go_oh
 
Powerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best PracticesPowerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best Practices
Dragos Ionita
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testing
Vikas Thange
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
Ankit Rastogi
 
JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101
ygv2000
 
JavaScript in Object-Oriented Way
JavaScript in Object-Oriented WayJavaScript in Object-Oriented Way
JavaScript in Object-Oriented Way
Chamnap Chhorn
 
A Re-Introduction to JavaScript
A Re-Introduction to JavaScriptA Re-Introduction to JavaScript
A Re-Introduction to JavaScript
Simon Willison
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript
Anjan Banda
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
Walid Ashraf
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
Bui Kiet
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
Adieu
 
Object Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptObject Oriented Programming in JavaScript
Object Oriented Programming in JavaScript
zand3rs
 
Object Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptObject Oriented Programming In JavaScript
Object Oriented Programming In JavaScript
Forziatech
 

Similar to Metaprogramming in JavaScript (20)

Metaprogramming in ES6
Metaprogramming in ES6Metaprogramming in ES6
Metaprogramming in ES6
Héctor Pablos López
 
OSCON - ES6 metaprogramming unleashed
OSCON -  ES6 metaprogramming unleashedOSCON -  ES6 metaprogramming unleashed
OSCON - ES6 metaprogramming unleashed
Javier Arias Losada
 
ES6 metaprogramming unleashed
ES6 metaprogramming unleashedES6 metaprogramming unleashed
ES6 metaprogramming unleashed
Javier Arias Losada
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
Binary Studio
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
Bruno Scopelliti
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
Julie Iskander
 
ES6: Features + Rails
ES6: Features + RailsES6: Features + Rails
ES6: Features + Rails
Santosh Wadghule
 
JavsScript OOP
JavsScript OOPJavsScript OOP
JavsScript OOP
LearningTech
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016
Manoj Kumar
 
Proxies are Awesome!
Proxies are Awesome!Proxies are Awesome!
Proxies are Awesome!
Brendan Eich
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6
Dmitry Soshnikov
 
JavaScript Essentials
JavaScript EssentialsJavaScript Essentials
JavaScript Essentials
Triphon Statkov
 
ES6: The future is now
ES6: The future is nowES6: The future is now
ES6: The future is now
Sebastiano Armeli
 
Intermediate JavaScript
Intermediate JavaScriptIntermediate JavaScript
Intermediate JavaScript
☆ Milan Adamovsky ☆
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScript
Stoyan Stefanov
 
Understanding-Objects-in-Javascript.pptx
Understanding-Objects-in-Javascript.pptxUnderstanding-Objects-in-Javascript.pptx
Understanding-Objects-in-Javascript.pptx
MariaTrinidadTumanga
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
Dmitry Soshnikov
 
WEB222-lecture-4.pptx
WEB222-lecture-4.pptxWEB222-lecture-4.pptx
WEB222-lecture-4.pptx
RohitSharma318779
 
Getting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascriptGetting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascript
Mohd Saeed
 
Introduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicoxIntroduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicox
David Rodenas
 
OSCON - ES6 metaprogramming unleashed
OSCON -  ES6 metaprogramming unleashedOSCON -  ES6 metaprogramming unleashed
OSCON - ES6 metaprogramming unleashed
Javier Arias Losada
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
Julie Iskander
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016
Manoj Kumar
 
Proxies are Awesome!
Proxies are Awesome!Proxies are Awesome!
Proxies are Awesome!
Brendan Eich
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6
Dmitry Soshnikov
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScript
Stoyan Stefanov
 
Understanding-Objects-in-Javascript.pptx
Understanding-Objects-in-Javascript.pptxUnderstanding-Objects-in-Javascript.pptx
Understanding-Objects-in-Javascript.pptx
MariaTrinidadTumanga
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
Dmitry Soshnikov
 
Getting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascriptGetting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascript
Mohd Saeed
 
Introduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicoxIntroduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicox
David Rodenas
 
Ad

Recently uploaded (20)

362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
djiceramil
 
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghjfHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
yadavshivank2006
 
New Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docxNew Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docx
misheetasah
 
Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401
Unknown
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Pavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible PavementsPavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible Pavements
Sakthivel M
 
Impurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptxImpurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptx
dhanashree78
 
3. What is the principles of Teamwork_Module_V1.0.ppt
3. What is the principles of Teamwork_Module_V1.0.ppt3. What is the principles of Teamwork_Module_V1.0.ppt
3. What is the principles of Teamwork_Module_V1.0.ppt
engaash9
 
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODSWIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
samueljackson3773
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
11th International Conference on Data Mining (DaMi 2025)
11th International Conference on Data Mining (DaMi 2025)11th International Conference on Data Mining (DaMi 2025)
11th International Conference on Data Mining (DaMi 2025)
kjim477n
 
IntroSlides-June-GDG-Cloud-Munich community [email protected]
IntroSlides-June-GDG-Cloud-Munich community gathering@Netlight.pdfIntroSlides-June-GDG-Cloud-Munich community gathering@Netlight.pdf
IntroSlides-June-GDG-Cloud-Munich community [email protected]
Luiz Carneiro
 
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptxDevelopment of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
aniket862935
 
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) ProjectMontreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Alexandra N. Martinez
 
How Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdfHow Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdf
Mina Anis
 
Présentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptxPrésentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptx
KHADIJAESSAKET
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Semi-Conductor ppt ShubhamSeSemi-Con.pptx
Semi-Conductor ppt ShubhamSeSemi-Con.pptxSemi-Conductor ppt ShubhamSeSemi-Con.pptx
Semi-Conductor ppt ShubhamSeSemi-Con.pptx
studyshubham18
 
Research_Sensitization_&_Innovative_Project_Development.pptx
Research_Sensitization_&_Innovative_Project_Development.pptxResearch_Sensitization_&_Innovative_Project_Development.pptx
Research_Sensitization_&_Innovative_Project_Development.pptx
niranjancse
 
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbbTree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
RATNANITINPATIL
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
djiceramil
 
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghjfHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
yadavshivank2006
 
New Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docxNew Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docx
misheetasah
 
Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401
Unknown
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Pavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible PavementsPavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible Pavements
Sakthivel M
 
Impurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptxImpurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptx
dhanashree78
 
3. What is the principles of Teamwork_Module_V1.0.ppt
3. What is the principles of Teamwork_Module_V1.0.ppt3. What is the principles of Teamwork_Module_V1.0.ppt
3. What is the principles of Teamwork_Module_V1.0.ppt
engaash9
 
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODSWIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
samueljackson3773
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
11th International Conference on Data Mining (DaMi 2025)
11th International Conference on Data Mining (DaMi 2025)11th International Conference on Data Mining (DaMi 2025)
11th International Conference on Data Mining (DaMi 2025)
kjim477n
 
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptxDevelopment of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
aniket862935
 
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) ProjectMontreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Alexandra N. Martinez
 
How Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdfHow Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdf
Mina Anis
 
Présentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptxPrésentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptx
KHADIJAESSAKET
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Semi-Conductor ppt ShubhamSeSemi-Con.pptx
Semi-Conductor ppt ShubhamSeSemi-Con.pptxSemi-Conductor ppt ShubhamSeSemi-Con.pptx
Semi-Conductor ppt ShubhamSeSemi-Con.pptx
studyshubham18
 
Research_Sensitization_&_Innovative_Project_Development.pptx
Research_Sensitization_&_Innovative_Project_Development.pptxResearch_Sensitization_&_Innovative_Project_Development.pptx
Research_Sensitization_&_Innovative_Project_Development.pptx
niranjancse
 
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbbTree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
RATNANITINPATIL
 
Ad

Metaprogramming in JavaScript

  • 2. Hello! I am Mehdi Valikhani Software Engineer at Autopilot
  • 4. “Metaprogramming is a programming technique in which computer programs have the ability to treat programs as their data. It means that a program can be designed to read, generate, analyse or transform other programs or itself while running source: Wikipedia
  • 5. “Metaprogramming is a programming technique in which computer programs have the ability to treat programs as their data. It means that a program can be designed to read, generate, analyse or transform other programs or itself while running source: Wikipedia
  • 7. “In computer science,reflection is the ability of a computer program to examine,introspect, and modify its own structure and behaviour at runtime. Reflection is a valuable language feature and it facilitates metaprogramming. source: Wikipedia
  • 8. Language features that enables reflection 1. Evaluate a string as if it were a source code statement at runtime. 2. Convert a string matching the symbolic name of a class or function into a reference to or invocation of that class or function. 3. Discover and modify source code constructions (such as code blocks, classes, methods, protocols, etc.) as first-class objects at runtime. source: Wikipedia
  • 11. Metaprogramming features of ES5 Code Evaluation eval() Examination ➔ instanceof ➔ typeof ➔ Object.getOwnPropertyNames() Modification Getter, setter
  • 14. Symbols The new type in JavaScript
  • 15. ➔ The seventh type of values in JavaScript Symbol ➔ The Symbol() function returns a value of type symbol ➔ Symbol() always returns unique values ➔ They may be used as an identifier for object properties source: MDN
  • 16. Example: Using Symbol as property identifier const nameField = Symbol('beer name'); const beer = { [nameField]: 'VB!' }; console.log(beer[nameField]); // -> VB!
  • 17. Example: Using Symbol as property identifier const nameField = Symbol('beer name'); const beer = { [nameField]: 'VB!' }; console.log(beer[nameField]); // -> VB!
  • 18. Example: Using Symbol as property identifier const nameField = Symbol('beer name'); const beer = { [nameField]: 'VB!' }; console.log(beer[nameField]); // -> VB!
  • 19. Example: Using Symbol as property identifier const nameField = Symbol('beer name'); const beer = { [nameField]: 'VB!' }; console.log(beer[nameField]); // -> VB!
  • 20. Well-known Symbols ➔ A set of built-in JavaScript symbols ➔ Represent internal language behaviours ➔ They were not exposed to developers before source: MDN
  • 21. Symbols are used by ES6 to enable “Reflection within implementation”. Developers include them on their existing classes and objects to change the default behaviour of an operation or action. source: keithcirkel.co.uk
  • 22. What can be done using well-known symbols ➔ Control the behaviour of instanceof for an implemented class ➔ Manipulate the behaviour of for of when iterated over a class ➔ Control over Array.concat ➔ Custom matches for String.match(), String.replace(), String.search() and String.split() ➔ Control the behaviour of Javascript when converting objects to primitive types Check MDN for a list of well-known symbols
  • 23. Example: Using well-known Symbol.hasInstance to modify behaviour of “instanceof” class MyArray { } const friends = ['foo', 'bar']; console.log(friends instanceof MyArray); // -> false class MyArray { static [Symbol.hasInstance](object) { return Array.isArray(object); } } const friends = ['foo', 'bar']; console.log(friends instanceof MyArray); // -> true
  • 24. Example: Using well-known Symbol.toPrimitive for a ShoppingBasket class class ShoppingBasket { constructor() { this.items = []; } add(title, quantity, price) { this.items.push({ title, quantity, price}); } total() { return this.items.reduce(function(accumulator, item) { return accumulator + (item.price * item.quantity); }, 0); } } } const basket = new ShoppingBasket(); basket.add('bread', 2, 2.5); basket.add('milk', 1, 1.4);
  • 25. Example: Using well-known Symbol.toPrimitive for a ShoppingBasket class class ShoppingBasket { constructor() { this.items = []; } add(title, quantity, price) { this.items.push({ title, quantity, price}); } total() { return this.items.reduce(function(accumulator, item) { return accumulator + (item.price * item.quantity); }, 0); } [Symbol.toPrimitive](hint) { if (hint === 'number') return this.total(); return this; } } const basket = new ShoppingBasket(); basket.add('bread', 2, 2.5); basket.add('milk', 1, 1.4); console.log(+basket); // -> 6.4 console.log(new Number(basket)); // -> 6.4
  • 26. Example: Using well-known Symbol.toPrimitive for a ShoppingBasket class class ShoppingBasket { constructor() { this.items = []; } add(title, quantity, price) { this.items.push({ title, quantity, price}); } total() { return this.items.reduce(function(accumulator, item) { return accumulator + (item.price * item.quantity); }, 0); } [Symbol.toPrimitive](hint) { if (hint === 'number') return this.total(); return this; } } const basket = new ShoppingBasket(); basket.add('bread', 2, 2.5); basket.add('milk', 1, 1.4); console.log(+basket); // -> 6.4 console.log(new Number(basket)); // -> 6.4
  • 27. Proxy
  • 28. Proxy, as the name indicates, provides “Reflection through interception”. It wraps objects and intercepts their behaviours through traps. source: keithcirkel.co.uk
  • 29. What can be done using Proxy ➔ A trap for delete operator ➔ Manipulate the behaviour of in operator ➔ Control over getting and setting property values ➔ A trap for function calls ➔ A trap for new operator Check MDN for a list of Proxy features
  • 30. Example: Implementation of a virtual field using Proxy const student = { firstName: 'Jackson', lastName: 'Rowe', }; const studentProxy = { get: function(object, fieldName) { if (fieldName === 'fullName') { return `${object.firstName} ${object.lastName}`; } return object[fieldName]; } }; const proxiedStudent = new Proxy(student, studentProxy); console.log(proxiedStudent.fullName); // -> Jackson Rowe
  • 31. Example: Implementation of a virtual field using Proxy const student = { firstName: 'Jackson', lastName: 'Rowe', }; const studentProxy = { get: function(object, fieldName) { if (fieldName === 'fullName') { return `${object.firstName} ${object.lastName}`; } return object[fieldName]; } }; const proxiedStudent = new Proxy(student, studentProxy); console.log(proxiedStudent.fullName); // -> Jackson Rowe
  • 32. Example: Implementation of a virtual field using Proxy const student = { firstName: 'Jackson', lastName: 'Rowe', }; const studentProxy = { get: function(object, fieldName) { if (fieldName === 'fullName') { return `${object.firstName} ${object.lastName}`; } return object[fieldName]; } }; const proxiedStudent = new Proxy(student, studentProxy); console.log(proxiedStudent.fullName); // -> Jackson Rowe
  • 33. Example: Implementation of a virtual field using Proxy const student = { firstName: 'Jackson', lastName: 'Rowe', }; const studentProxy = { get: function(object, fieldName) { if (fieldName === 'fullName') { return `${object.firstName} ${object.lastName}`; } return object[fieldName]; } }; const proxiedStudent = new Proxy(student, studentProxy); console.log(proxiedStudent.fullName); // -> Jackson Rowe
  • 34. Example: Value validation using Proxy const student = { firstName: 'Jackson', lastName: 'Rowe', }; const studentProxy = { set: function(object, fieldName, value) { // validation logic for the “age” field if (fieldName === 'age') { if (typeof value !== 'number') { throw TypeError('only numbers are accepted'); } if (value <= 0) throw TypeError('that is impossible'); } object[fieldName] = value; return true; } }; const proxiedStudent = new Proxy(student, studentProxy); proxiedStudent.age = 'a'; // errors proxiedStudent.age = -1; // errors proxiedStudent.age = 12; // does not error
  • 35. Example: Value validation using Proxy const student = { firstName: 'Jackson', lastName: 'Rowe', }; const studentProxy = { set: function(object, fieldName, value) { // validation logic for the “age” field if (fieldName === 'age') { if (typeof value !== 'number') { throw TypeError('only numbers are accepted'); } if (value <= 0) throw TypeError('that is impossible'); } object[fieldName] = value; return true; } }; const proxiedStudent = new Proxy(student, studentProxy); proxiedStudent.age = 'a'; // errors proxiedStudent.age = -1; // errors proxiedStudent.age = 12; // does not error
  • 36. Example: Value validation using Proxy const student = { firstName: 'Jackson', lastName: 'Rowe', }; const studentProxy = { set: function(object, fieldName, value) { // validation logic for the “age” field if (fieldName === 'age') { if (typeof value !== 'number') { throw TypeError('only numbers are accepted'); } if (value <= 0) throw TypeError('that is impossible'); } object[fieldName] = value; return true; } }; const proxiedStudent = new Proxy(student, studentProxy); proxiedStudent.age = 'a'; // errors proxiedStudent.age = -1; // errors proxiedStudent.age = 12; // does not error
  • 37. Example: Value validation using Proxy const student = { firstName: 'Jackson', lastName: 'Rowe', }; const studentProxy = { set: function(object, fieldName, value) { // validation logic for the “age” field if (fieldName === 'age') { if (typeof value !== 'number') { throw TypeError('only numbers are accepted'); } if (value <= 0) throw TypeError('that is impossible'); } object[fieldName] = value; return true; } }; const proxiedStudent = new Proxy(student, studentProxy); proxiedStudent.age = 'a'; // errors proxiedStudent.age = -1; // errors proxiedStudent.age = 12; // does not error
  • 38. Example: Protect “id” field from deletion using a Proxy const student = { id: 'jackson-rowe', firstName: 'Jackson', lastName: 'Rowe', }; const studentProxy = { deleteProperty: function(object, fieldName) { if (fieldName === 'id') return false; delete object[fieldName]; return true; } }; const proxiedStudent = new Proxy(student, studentProxy); delete proxiedStudent.id // -> false console.log(proxiedStudent.id); // jackson-rowe
  • 39. Example: Protect “id” field from deletion using a Proxy const student = { id: 'jackson-rowe', firstName: 'Jackson', lastName: 'Rowe', }; const studentProxy = { deleteProperty: function(object, fieldName) { if (fieldName === 'id') return false; delete object[fieldName]; return true; } }; const proxiedStudent = new Proxy(student, studentProxy); delete proxiedStudent.id // -> false console.log(proxiedStudent.id); // jackson-rowe
  • 40. Example: Protect “id” field from deletion using a Proxy const student = { id: 'jackson-rowe', firstName: 'Jackson', lastName: 'Rowe', }; const studentProxy = { deleteProperty: function(object, fieldName) { if (fieldName === 'id') return false; delete object[fieldName]; return true; } }; const proxiedStudent = new Proxy(student, studentProxy); delete proxiedStudent.id // -> false console.log(proxiedStudent.id); // jackson-rowe
  • 41. Example: Protect “id” field from deletion using a Proxy const student = { id: 'jackson-rowe', firstName: 'Jackson', lastName: 'Rowe', }; const studentProxy = { deleteProperty: function(object, fieldName) { if (fieldName === 'id') return false; delete object[fieldName]; return true; } }; const proxiedStudent = new Proxy(student, studentProxy); delete proxiedStudent.id // -> false console.log(proxiedStudent.id); // jackson-rowe
  • 43. Reflect is all about “Reflection through introspection” - provides API to discover very low level information about code. source: keithcirkel.co.uk
  • 44. What can be done using Reflect ➔ Call a function using Reflect.apply() ➔ Define a property using Reflect.defineProperty() ➔ Delete a property using Control over Reflect.deleteProperty() ➔ Get a property value using Reflect.get() ➔ Set property value using Reflect.set() ➔ Check if a property exist using Reflect.has() Check MDN for a list of Reflect features
  • 45. What Reflect object offers are either a newer versions of existing methods or entirely new methods - allowing new levels of Reflection within JavaScript. source: keithcirkel.co.uk
  • 46. Example: Deleting a property using Reflect.deleteProperty() const student = { firstName: 'Jackson', lastName: 'Rowe', }; console.log(student.firstName); // -> Jackson Reflect.deleteProperty(student, 'firstName'); console.log(student.firstName); // -> undefined
  • 47. Example: Deleting a property using Reflect.deleteProperty() const student = { firstName: 'Jackson', lastName: 'Rowe', }; console.log(student.firstName); // -> Jackson Reflect.deleteProperty(student, 'firstName'); console.log(student.firstName); // -> undefined
  • 48. Example: Deleting a property using Reflect.deleteProperty() const student = { firstName: 'Jackson', lastName: 'Rowe', }; console.log(student.firstName); // -> Jackson Reflect.deleteProperty(student, 'firstName'); console.log(student.firstName); // -> undefined
  • 49. Example: Deleting a property using Reflect.deleteProperty() const student = { firstName: 'Jackson', lastName: 'Rowe', }; console.log(student.firstName); // -> Jackson Reflect.deleteProperty(student, 'firstName'); console.log(student.firstName); // -> undefined
  • 50. 100%Modern Browsers (Edge, Firefox, Safari, Chrome) 0%IE 11 100%Node 8 source: http://kangax.github.io/compat-table/es6/ Native support
  • 51. Resources ● Wikipedia - Metaprogramming ● Wikipedia - Reflection in Computer Science ● Mozilla - Metaprogramming ● Metaprogramming in ES6 by Keith Cirkel
  • 52. Credits Special thanks to all the people who made and released these awesome resources for free: ▷ MDN web docs ▷ Wikipedia and the contributors ▷ Keith Cirkel for the Metaprogramming series ▷ Presentation template by SlidesCarnival
  • 53. Thanks! Any questions? You can find me at: ➔ @mehdivk ➔ linkedin.com/in/valikhani/ ➔ [email protected]