how to create a setter function on a javascript object literal #shorts
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
————
🤑 Patreon https://www.patreon.com/webdevjunkie
🔔 Newsletter http://eepurl.com/hnderP
💬 Discord https://discord.gg/4kGbBaa
📁. GitHub https://github.com/codyseibert/youtube
Need some design pattern videos!! Super helpful thanks.
Does anyone experienced Fatal error in, line 0 fatal JavaScript invalid size error 16922084, I haven't get this error before, happened to me last night me when I was running npm start after adding border on my form on project that am working on using react framework, and I have tried different approach provided but can get it fixed
line 13 why split(" ") is used? without split also output is same 😟!
Wow, that's impressive, I didn't knew about that! Thanks!
One of the topics I don't get haha 😅
Rip Bob
Apk?
can't you access firstName and lastName directly? anyway to make them private?
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.
[this.firstName, this.lastName] = newName.split(" "); is shorter
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.
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.
thank you my freind
i am beginner in javascript so i want to know what extention you use for javascript while yo setting up your vs code
What extension you use that you get error get displayed in same line?
Can you please be posting this on your instagram?? And what's your instagram account?
Good job babe!!!
Fun fact: you can destructure directly into nested objects (e.g. 'this.firstName')
[this.firstName, this.lastName] = newName.split(' ');
What plug-in are you using to show suggestions and errors to the right?
RIP Bob Saget
How do you console inside your terminal?
Nice video BTW
Some example use cases would be much appreciated, haven't used those in 2yrs of js dev.. thanks for the video!!
Very well explained usage of getters and setters 👍 Everybody's a critic pointing out "issues" with the example 😂🤦🏻♂️
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!
This is great until someone tries to set a name without a space and causes a runtime error
I could test this out later but one question. Lets say i make an API call and get a JSON list of objects. Can i iterate on each object and add a "set" to each one?
This is awesome. Btw you do look like Bob Sagot lmao
Haha, Rick James. I always think of that Chapelle show skit when I hear that name.
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 😂
It makes no sense to add a setter if the firstName property is able to be accessed directly. One way to protect the firstName prop is to return the getters/setters as closures.
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
So assigning a value to a function prefixed by set will treat it as passing a param basically?
Keep up the good work, this is great.
baaaad. lookup ddd
Bob Saget*
Would be hard for you to merge all those amazing videos by topic?