Yes, that's exactly what object literal means. A definition of a javascript object which may contain comma separated definition of properties, functions, ...
Answer from Darin Dimitrov on Stack OverflowObject literals are formed using the following syntax rules:
- A colon separates property name from value.
- A comma separates each name/value pair from the next.
- There should be no comma after the last name/value pair. Firefox won't object if you add it, but Internet Explorer will trigger an error: 'Expected identifier, string or number'.
Yes, that's exactly what object literal means. A definition of a javascript object which may contain comma separated definition of properties, functions, ...
Object literals are formed using the following syntax rules:
- A colon separates property name from value.
- A comma separates each name/value pair from the next.
- There should be no comma after the last name/value pair. Firefox won't object if you add it, but Internet Explorer will trigger an error: 'Expected identifier, string or number'.
An object literal is a way to declare an object.
You would write
var myObject = {}; // with or without members
instead of
var myOject = new Object();
You can also use array literals:
var myArray = [];
instead of
var myArray = new Array(); // with or without members
It's shorter, of course but it also bypasses the constructor so it's supposed to be more efficient.
About "complimenting JSON": He specified it.
The "literal" part: Googling "object literal" provides two top resources: MDN and Wikipedia. To quote the latter:
In computer science, a literal is a notation for representing a fixed value in source code. Almost all programming languages have notations for atomic values such as integers, floating-point numbers, and strings, and usually for booleans and characters; some also have notations for elements of enumerated types and compound values such as arrays, records, and objects.
Basically, all syntax constructs whose use lead to a defined type can be called a literal. (E.g., a string literal, "abc".) It's a technical term that denotes, that "literally" writing something in this or that way leads to a certainly typed variable exclusively (in contrast to constructs, that look like something else, like array() in PHP).
Well, in programming in general a literal is a fixed value.
Like saying var five = 5; and using "five" in some math, just use the number 5 literally.
So in an OOP language an object literal would be something like:
var new_dog = {
name: "doggy",
good_dog: false
};
The entire thing is my object. Things between my {} are my literals. My notation is a pattern "name:value".