Organizing and Simplifying JavaScript with Object Literals - 12
- Posted: Aug 06, 2012 at 10:29 AM
- 23,820 Views
- 3 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Right click “Save as…”
Developers coming from Object Oriented Programming backgrounds may notice similar constructs (objects, the new keyword, etc.), but in JavaScript these ideas are implemented much differently. This video demonstrates the creation of simple objects called "object literals" to keep related properties and functions (methods) together in one structure. Finally, Bob demonstrates using constructors and the new keyword to show how different these ideas are from other programming languages.
Already have a Channel 9 account? Please sign in
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?
Re-opening this closed thread ...
You say that "status:" and "rescueBatman:" are variables, so why do you use ":" to define the variable, why can't you use "="?
also you don't explain object literal very well, this is supposed to be for Absolute Beginners and you were speaking about it as if we have previous knowledge like with C# and it sounds very complicated so this lesson really did nothing for me while the other previous ones have been good.
@Lee Wood: Hey Lee, sorry this video didn't do a very good job of explaining it. If / when I ever re-do this video, I'll pay more attention to how I go about this. Thanks for the feedback.
If I said that those object members are "variables", that was a misstatement and I apologize. They are MEMBERS of an object. Objects can have properties (attributes) and methods (functionality). In this case, "status" is a property / attribute, and "rescueBatman" is a method. Both are members of the whole, of the new object. We set a reference to that new object using the equals = operator.
Why use a colon : and not an equals = operator? Here are two examples that are functionality equivalent:
var myObject = { firstProperty:'some value', secondProperty:'some other value'};.. is functionally the same as:
You'll see the former syntax (with the colon : ) more often in JavaScript because it is so compact. In fact, as you learn more, you'll that this is the defacto way to pass data between servers and web browser clients using this exact style of syntax, called JSON (IavaScript Object Notation) BECAUSE it is so compact. More about that in an upcoming video.
Hope that helps? Please feel free to follow up ... we'll get to the bottom of this!
Remove this comment
Remove this thread
close