An Object within an Object

nesting dolls

Share This Post

One thing that is helpful to learn when programming in JavaScript is that nearly everything is an object. We can then use objects to create other objects. Sort of like a copying of the data. It is not a complete “copy and paste”, which I will blog about later, but what I wanted to concentrate on in this post is what this functionality gives us.

We can have an object called a constructor wherein we set up the blueprint for our object. I will go into details of a constructor in a future post. In this one, I simply want you to grasp the power and ease of code reuse with objects within an object and how that allows us to build robust code.

For example, say we have a constructor entitled, “Blog”. Notice the caps…all constructors are supposed to be capitalized. This is not enforced by the language but is a generally accepted convention. Within this Blog constructor, there are two properties…one for holding a date object and one for holding the string of the actual post content.

We can then create an individual blog entry by utilizing the Blog constructor object. It might look like this…

// Create a variable to hold a blog entry
var blogEntry = new Blog(“Something interesting written here.”, new Date("10.31.2016"));

Notice the “new” keyword. This tells JavaScript, “Hey, I am creating something new here. In fact, it is a new instance of the Blog constructor object. So copy all of the necessary stuff for me.”

As I stated earlier, the Blog constructor took two properties…date and string. We can create/pass those along as parameters for the constructor. We now have an individual blog entry.

So why is this important? Within the constructor, we can encapsulate any logic specific to that object…built-in methods, properties, etc. This allows for easier code maintenance and maintains our logic and structure.

Happy Coding!

Clay Hess

More To Explore


Demystifying Scrum User Stories Confirmation: Ensuring Quality and Collaboration

One of the key elements of Scrum is the use of user stories to define the requirements of a system or feature from the perspective of the end user. As teams work through the product backlog, it becomes crucial to confirm the user stories to ensure they meet the desired criteria and are ready for development. In this blog post, we’ll explore the concept of Scrum user stories confirmation and its significance in delivering high-quality products.


The Power of Conversations in Scrum User Stories

At the heart of Scrum lies the concept of user stories, which serve as a means of capturing requirements from the perspective of end-users. However, the true power of user stories lies not just in their written form but also in the conversations that take place around them. In this blog post, we will explore the significance of conversations in Scrum user stories and how they contribute to the success of Agile projects.

Do You Want To Boost Your Business?

drop us a line and keep in touch

Scroll to Top

Need help?

Let's have a chat...


Jump Back In!

Here at Webolution Designs, we love to learn. This includes sharing things we have learned with you. 


Begin Your Learning Journey Today!

Come back inside to continue your learning journey.