curriculum
curriculum copied to clipboard
Update reflect-api-in-es6.md
I think this example is misleading because who uses .apply
that way even with ES5?
Commonly, the call is: func.apply(thisArg, args)
And compared to that, using Reflect is less, not more concise.
Insight previews:
- [ ] https://enkipro.compreview-insight/enkidevs/curriculum/javascript/ecmascript-2015/master-es6-features/reflect-api-in-es6.md?ref=130c517a32ff4173281c41dccadce8e9ea0900ab
Hey @s-h-a-d-o-w - Agreed, that example is kinda weird, but I find the article hard to understand without it. There are two really short, very abstract examples, but we need something real to show when you might use this thing. Do you know of a good (tiny) example?
Haha well... I have to say that I don't find much day-to-day use for many of those hyped ES6 language features. And instead time and time again see examples of people trying to cram them in somewhere just because they're new and exciting. In fact, I saw a good example for that as I was researching a bit - someone argued that this is great use of Reflect:
const greetingFactory = (name) => Reflect.construct(Greeting, [name]);
And wrote an unnecessarily convoluted ES5 version to prove their point when really, this works just fine as well (arrow functions are an awesome ES6 feature though... :wink: ):
const greetingFactory = (name) => new Greeting(name);
But... I guess the following one is quite nice - getting a return value when defining a property instead of having to try/catch? https://ponyfoo.com/articles/es6-reflection-in-depth#return-values-in-reflect-vs-reflection-through-object
That's the only thing I could find that one might reasonably use though. All other things were more along the lines of "The semantics are cleaner because it's now in Reflect" - but the functionality is largely the same as when doing e.g. Object.getOwnPropertyDescriptor().