how to create a setter function on a javascript object literal #shorts

how to create a setter function on a javascript object literal #shorts

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
🔔 Newsletter
💬 Discord
📁. GitHub


  1. 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

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

  3. 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.

  4. 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.

  5. 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.

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

  7. Can you please be posting this on your instagram?? And what's your instagram account?

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

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

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

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

  11. 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!

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

  13. 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?

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

  15. 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 😂

  16. 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.

  17. 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

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

Leave a Reply

Your email address will not be published. Required fields are marked *

© 2023 53GB - WordPress Theme by WPEnjoy