How to use javascript symbols to overwrite default iteration behavior #shorts

preview_player
Показать описание
My VSCode Extensions:
- theme: material community high contrast
- fonts: Menlo, Monaco, 'Courier New', monospace
- errors: Error Lens
- extra git help: Git Lens
- tailwind css intellisense
- indent rainbow
- material icon theme
- prettier & eslint
- ES7+ React Snippets

------------

Рекомендации по теме
Комментарии
Автор

The more i watch these, the more i become sure i have no idea about javascript and i have been working with it for almost 5 years😭😭😭

noonecares
Автор

That's really cool. It's an incredible anti-pattern, but really cool

modernkennnern
Автор

Wow! I have been looking for this for months! Thanks!

polar
Автор

This is one of those cases where we have to call whoever developed the JavaScript programming language to explain what they were thinking when they included this 😂 Like in which case scenario would I wanna use this??

mulwelimushiana
Автор

Reels is so suck, my screen cut sides and I can’t see all

danilowm
Автор

The purpose of this generator function could also be to simulate Python's range type, which really only stores 3 numbers: the start point, the end point, and the step (all numbers in between are programmatically determined).

C.Ezra.M
Автор

This is useful for map-like objects, for example, or other types of collections. The "properties" of a mapping have absolutely no bearing on the actual content of the mapping itself. It makes perfect sense to want this functionality; the example was simply a toy one to demonstrate how it works and I think it obscured the actual reason this exists in the first place.

omniarexsum
Автор

You can define the property within the object initializer itself too!

{
// ...
[Symbol.iterator]: function * generator() {
// Generator code here
}
}

Zooiest
Автор

wish we were able to overwrite other stuff to
for example what happens when i use +-/* operators
or image if you can rewrite = operator have a property with a getter and setter without putting it inside another object

nomadshiba
Автор

What are the practical uses of this and symbols in general

omomer
Автор

Symbol.iterator is what makes ab object iterator

Trademm
Автор

Would be better to show a real world use case cos from this example i can't tell if this is a useful feature or not

engine_man
Автор

Would recommend Quokka to output your console logs inline and hide the terminal

TheProcessor
Автор

is it possible to asign values in the same way?

Jesus_.
Автор

the output of your code is not visible bro work in it

gaganbaghel
Автор

If I would try to access name or age what would happen then?

Ish-YouTube
Автор

If someone of you does that I will be very angry after hours of debugging!

simonkraemer
Автор

Is there a way to dynamically set the yield statements or will this always be hardcoded

zendude
Автор

Nice info dude, but i think this kind of code will rarely be used in real project. Maybe you can make tutoria about something that people can relate, and how to make it easier.

akbarumar
Автор

That’s awesome, another piece of code that I’ll get scolded for

Joelitop