Aloysious' Codefellows Reading Notes
<== Previous Lesson Next Lesson ==>
<== Home 🏠
<table>
element is used to add tables to a web page.<tr>
element.<td>
element(or <th>
if it is a header).<thead>
[table head] <tbody>
and <tfoot>
.In real life, a car is an object.
A car has properties like weight and color, and methods like start and stop:
Object Properties Methods
car.name = Fiat
car.model = 500
car.weight = 850kg
car.color = white
car.start()
car.drive()
car.brake()
car.stop()
All cars have the same properties, but the property values differ from car to car.
All cars have the same methods, but the methods are performed at different times.
JavaScript variables are containers for data values.
This code assigns a simple value (Fiat) to a variable named car:
var
car
= "Fiat";
Objects are variables too. But objects can contain many values.
This code assigns many values (Fiat, 500, white) to a variable named car:
var
car
= {type:"Fiat", model:"500", color:"white"};
The values are written as name:value pairs (name and value separated by a colon).
JavaScript objects are containers for named values called properties or methods.
Object Definition
You define (and create) a JavaScript object with an object literal:
Example
var
person
= {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
Spaces and line breaks are not important. An object definition can span multiple lines:
Example
var person = {
firstName: “John”,
lastName: “Doe”,
age: 50,
eyeColor: “blue”
};
Object Properties
The name values:pairs in JavaScript objects are called properties:
Property Property Value
firstName John
lastName Doe
age 50
eyeColor blue
Accessing Object Properties
You can access object properties in two ways:
objectName.propertyName
or objectName["propertyName"]
In a function definition, this refers to the “owner” of the function.
In the example above, this is the person object that “owns” the fullName function.
In other words, this.firstName
means the firstName property of this object.
JavaScript methods are actions that can be performed on objects.
A JavaScript method is a property containing a function definition.
From the Duckett HTML book:
From the Duckett JS Book:
<== Previous Lesson Next Lesson ==>
<== Home 🏠