Skip to content

Commit

Permalink
feat(reflect): add part about Reflect (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xartok authored Apr 30, 2024
1 parent 2857578 commit 45a3612
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/markdown/08b-reflect/00-TITLE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- .slide: class="transition red" -->

# Reflect
20 changes: 20 additions & 0 deletions docs/markdown/08b-reflect/01-Purpose.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!-- .slide: class="with-code" -->

# Reflect - Objectifs

L'API Reflect permet de faire de l'introspection sur les objets. Elle propose notamment des fonctions reprenant le
comportement des opérateurs `new` ou `in`.

```javascript
const symbol = Symbol('foo');
class C {
constructor(foo) {
this.foo = foo;
this[symbol] = foo;
}
}
let object = Reflect.construct(C, ['bar']);
Reflect.has(object, 'foo'); // true
Reflect.has(object, symbol); // true
Reflect.get(object, 'foo'); // bar
```
4 changes: 4 additions & 0 deletions docs/markdown/08b-reflect/02-All-Functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- .slide: class="full-center" -->
# Reference

https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Reflect
13 changes: 13 additions & 0 deletions docs/markdown/08b-reflect/03-Interesting-Methods-Examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- .slide: class="with-code" -->

# Interesting examples - OwnKeys

```JS
const obj = {
[Symbol("test")]: "test",
foo: "bar",
};

Reflect.ownKeys(obj); // ["foo", Symbol(test)]
Object.keys(obj) // ["foo"]
```
9 changes: 9 additions & 0 deletions docs/scripts/slides.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ const proxySlides = () => [
`${proxySlidesDir}/02-Exercice.md`,
];

const reflectSlidesDir = '08b-reflect';
const reflectSlides = () => [
`${reflectSlidesDir}/00-TITLE.md`,
`${reflectSlidesDir}/01-Purpose.md`,
`${reflectSlidesDir}/02-All-Functions.md`,
`${reflectSlidesDir}/03-Interesting-Methods-Examples.md`,
]

const modulesSlidesDir = '09-modules';
const modulesSlides = () => [
`${modulesSlidesDir}/00-TITLE.md`,
Expand Down Expand Up @@ -132,6 +140,7 @@ function formation() {
...iteratorGeneratorSlides(),
...symbolSlides(),
...proxySlides(),
...reflectSlides(),
...modulesSlides(),
...typescriptSlides(),
...functionalJavascriptSlides(),
Expand Down

0 comments on commit 45a3612

Please sign in to comment.