Beruflich Dokumente
Kultur Dokumente
They are
inmany ways the same subject.
Objects are a collection of name value pairs. and those values can be other
collections of name-value pairs.
an object can have another object connected to it - that is another property. This
is called a child.
An object can also contain functions, these are called methods. It is a function
but is connected to an object so it is called a method.
So an object is something that sits in memory which has referneces to other things
connected to it in the memory.
code:
var person = new Object(); //creating a new object
This is one way to set an object property. See Operator precednce top 3. The []
operator takes the object name and the property name as parameters.*/
person["lastname"] = "Alicea";
console.log(person);
console.log(person[firstNameProperty]);
output:
{firstname: "Tony", lastname: "Alicea"}firstname: "Tony"
lastname: "Alicea"
__proto__: Object
Tony
code:
var person = new Object(); //creating a new object
person["firstname"] = "Tony";
person["lastname"] = "Alicea";
console.log(person);
console.log(person[firstNameProperty]);
.: person["firstname"] == person.firstname
.: person["address"]["state"] == person.address.state
these dots and brackets are just functions. operators. obejcts are just things in
memory woth reference to to other things in memory.
the preffered approach is the dot. more readable. unless you want to access the
object via string