how to create a setter function on a javascript object literal #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

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

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

Need some design pattern videos!! Super helpful thanks.

chinmayh
Автор

Fun fact: you can destructure directly into nested objects (e.g. 'this.firstName')

[this.firstName, this.lastName] = newName.split(' ');

jacksonbourne
Автор

Very well explained usage of getters and setters 👍 Everybody's a critic pointing out "issues" with the example 😂🤦🏻‍♂️

secret-alias
Автор

Keep up the good work, this is great.

alpha_calculus
Автор

Some example use cases would be much appreciated, haven't used those in 2yrs of js dev.. thanks for the video!!

kaloianangelkov
Автор

This is great until someone tries to set a name without a space and causes a runtime error

crvlwanek
Автор

Wow, that's impressive, I didn't knew about that! Thanks!

shadowplay
Автор

Works well only in case when first name and last name presented as 2 words. If you pass some kind of spanish-like person full name you may face a difficulties with a double last names.

xaykes
Автор

The example is... eh... not great, but the information was conveyed properly. I often use setters to trigger events and such. Especially at work where we mostly use vanilla JS with no framework. It is nice for separating data from page updating.

CottidaeSEA
Автор

Can you make a small series on why do even need X over Y?

Suppose, here, you can use a setter to set the name, but you could've done the same thing by literally setting both properties manually

bunnyboy
Автор

Good video talking about how to use getters and setters. Just a note, there are quite a few last names with more than 2 words in it. And someone decided te also add the middle name, there would be no way to determine where the split between first and last name is. Minor nitpick though. Keep it up!

samuelbarkley
Автор

Haha, Rick James. I always think of that Chapelle show skit when I hear that name.

JJTrades_X
Автор

It's actually an abstract example. So the code is really nice. But for this problem is still problematic due to names. It won't work for multiple first names and for 2 part of last name (for example Ulrich von Jungingen, whete "von Jungingen" should be tracted possibly as last name. But sure, I understand it's just an example how to use js. But I had to mention it 😂

nowieszco
Автор

Would be hard for you to merge all those amazing videos by topic?

moneyfr
Автор

This is awesome. Btw you do look like Bob Sagot lmao

kevyyar
Автор

As someone coming from strictly typed languages this code looks like it will release the entire earth's population of bugs.
1. No guarantees that you even get a string as the argument
2. No guarantees that the string contains 2 space split substrings
3. No guarantees the function argument is not null or undefined.
I will definitely never touch js in my life. If I need a webapp it will be written in web assembly based on rust.

redcrafterlppa
Автор

i am beginner in javascript so i want to know what extention you use for javascript while yo setting up your vs code

ahmedmohammed-wiqp
Автор

line 13 why split(" ") is used? without split also output is same 😟!

aliensoul
Автор

So assigning a value to a function prefixed by set will treat it as passing a param basically?

nimmneun
Автор

can't you access firstName and lastName directly? anyway to make them private?

pipzgutz
join shbcf.ru