How to validate an object using a Proxy class #shorts

preview_player
Показать описание
Showing a cool trick to use the proxy class to validate an object's properties when they change.

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

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

Actually, that's really cool. Being able to create your own validator.

Crohm
Автор

You don’t even need a proxy or a class. You can just define setters on object either via a "{ set field(value) { … } }" syntax, or via

I find proxies useful when intending to override operators (like providing value equality for objects) or when trying to trace properties we don’t know about in advance.

yapet
Автор

Getting your channel was the hidden JS Gem
Like how did I not know about this 😅😂
Thanks a lot

_Cyrus
Автор

damn. this is kind of what I miss from programming languages like Java. this is a great solution, thank you!

jesusdaaav
Автор

I would just use a class for Person as you can apply this very logic inside the definition

dfcw
Автор

this is a lifesaver, but now TS can handle this with much easier syntax

gyanshodhak
Автор

Proxies are cool, I’ve seen a useRef, context and proxies implement of global state

VKD
Автор

Looks like a longwinded way of doing simple OOPS accessor mutator logic. Js has done it again, reinventing the wheel

sayanghosh
Автор

This guy is awesome no other Youtuber taught me all the hidden features of Js can you do more of React.

dotmv
Автор

Did not know about this. Great! I have used the checkvalidity on inputs and that works great too. Also takes regex thru its params

AndrewTSq
Автор

Just use a class with private properties, and add a setter which contains the validation

Naej
Автор

Wooh ❤ I can’t believe how little i know about JavaScript

mcperera
Автор

Good to know, I wish it was handled as cleanly and as simple as in C# or Java.

zimcoder
Автор

That's a whole lot of code for just a setter function

duarteribeiro
Автор

Today I learned something new and useful

SpaghettiRealm
Автор

Seems to very much function like decorators, thanks for sharing

MrBrandenS
Автор

I like it, videos like these are nice

ll_dutch
Автор

I did not know this. That's awesome asf 👏

perfect.stealth
Автор

that's really cool, I wasn't aware of this.

bogdanstanciu
Автор

It's look difficult but useful. Thanks brooo

soulking
visit shbcf.ru