Name It…It’s Yours

clone

Share This Post

In my previous post, I spoke about JavaScript objects. An object is simply a named collection of properties and methods. It can contain primitive data types, such as numbers, text and booleans. It can also contain complex data types, such as arrays, functions and even other objects.

So why mess with all of this object junk? Why not put everything in the global scope so you can access anything you want at any time? The answer is encapsulation. This is an object-oriented principle which speaks to the protection and organization of your data. If everything is in the global scope, everything is open for changing in your program and not logically organized. So you want as little global as possible. So objects give our data and program pieces more meaning and context.

JavaScript has its own built-in, standard objects, but you can also create your own custom objects. This is easily accomplished using constructors. A constructor is like a blueprint for an object. Its job is to establish properties and methods of an object. It can even set initial values of its properties. Here is an example…

function Invitation(who. what. when, where) {
	this.who = who;
	this.what = what;
	this.when = when;
	this.where = where;
}

Notice the “this” keyword. The “this” keyword allows us to refer to the context of properties. Basically, it means that the value of a property belongs to “this” constructor. For example, this.who is a property of “this” Invitation constructor.

Another thing to note is the capital “I”. In JavaScript, you typically begin with lowercase, but when it comes to constructors, you use uppercase. This is not strictly enforced, but is a standard convention.

So how do constructors help us? As I stated, they are blueprints to instantiate other objects. So we copy objects from objects. Here is an example using our Invitation constructor…

// Store the new object in a variable (invitation)
var invitation = new Invitation("Joe Schmoe", "Birthday Party", "December 12, 2017", "Jane's House");

We now can access a new instance of the Invitation object with all of the new values we passed to it.

Happy Coding!

Clay Hess

More To Explore

Code

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.

Code

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
small_c_popup.png

Need help?

Let's have a chat...


Login

Jump Back In!

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

Register

Begin Your Learning Journey Today!

Come back inside to continue your learning journey.