Objects in a Nutshell

by Nick Jensen on October 22, 2013

I swear, reading John Pollock’s JavaScript: A Beginner’s Guide feels like navigating through some dark jungle in the middle of the Congo. Unfortunately, unlike Heart of Darkness‘s Marlow, I don’t have a river to navigate by. And like any jungle, this book becomes increasingly difficult to navigate through as I venture deeper into it. So, like any smart adventurer, I have brought a guide to help me navigate through this torturously confusing book on JavaScript. What kind of guide have I brought with me? The internet. Google can often, if not always, explain abstract JavaScript concepts much more efficiently than Mr. Pollock. The problem with Pollock’s book starts with his long-winded explanations that are riddled throughout each chapter. I simply want to understand what each object does. That being said, I have learned the fundamentals of objects.

Objects are simply a set of different values which define a variable. To give you a better idea of what I mean, imagine you see a dog. You first notice that the dog is brown. After that, you notice that he has a tennis ball in his mouth. Finally, you notice that he’s a friendly dog as he drops his ball by your feet, hoping that you will pick it up and throw it for him. In this case, the dog is our variable and the object attached to that variable is the dog’s characteristics (brown fur color, fondness for tennis balls, and friendly demeanor).

var dog = {

friendly: “loves people”,

ball: “begs people to play fetch”,

brown: “has soft brown fur”

};

document.write( “Fred just ” + friendly + “. He ” + brown + “and ” + ball + ” with him.”);

“Fred just loves people. He has soft brown fur and begs people to play fetch with him.”

Of course, working with objects can become very tricky. I, myself, still have much to learn. While you can create objects with interchangeable values, doing so requires two components: constructors and prototypes. Constructors compliment objects by preparing its properties, similar to the example above.  Prototypes are actually objects themselves and they determine the characteristics and capabilities of other objects. Playing around, err….I’m sorry, working with prototypes and constructors can be a frustratingly tedious process for those who are new to JavaScript (that would include me, by the way). Unfortunately, these blogs cannot substitute learning JavaScript on your own, whether it be from a book or the internet. This chapter on objects is littered with way too many examples of JavaScript code and as I am finding out, trying to explain JavaScript concepts without code is almost as hard as writing a manual without the luxury of images.

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: