code fellows 201
Objects are like data base objects. It is like a personel folder that stores various forms of information. Properties are variables stored within an object. Methods, like properties to variables, are what you call functions stored in an object.
// example of object named hotel
var hotel = {
// these are properties
name: 'Quay',
rooms: 40 '
booked: 25,
gym: true,
roomTypes: ['twin', 'double', 'suite'],
// this is a method
checkAvailability: function() {
return this.rooms - this.booked;
}
};The key is how you define the variables and functions. they are on the left side of the ':'. The values are what is contained within the key, there are what follows the ':'.
There are 2 ways to acces an object, dot notations and the square bracket method.
var hotelName = hotel.name;
var roomsFree = hotel.checkAvailability();
The property to the right of the . is within the object stated on the right. The variable on the left is declared to hold the information of the object called.
var hotelName = hotel['name'];
var roomsFree = hotel['checkAvailability']();
You use this notation when:
- name of property contains special characters like a dash
- name of property is a number
- a variable is used in place of property name
The Document Objective Model (DOM) is a visual representation of how browsers create HTML pages and how JavaScript acesses and updates contents in the page.
When you load an html file the browser creates a mode that is stored in the browser's memory. This is a DOM tree. It has four main nodes:
The Document Node is the starting point of the tree. It sits at the top. It represents the entire page as a whole.
The Element Node