Problem Domain, Objects, and the DOM
Understanding the problem
- familiarty can take away from the problem domain and make learning easier
- writing code is like putting together a jigsaw puzzle. if you take one problem at a time putting together the code or picture is easier.
- understanding the problem is a big part of writing code
- if you can do that it makes thing much easier
- cut out cases and narrow your focus to one part of the problem
Object Literals
- if a variable is part of an object it is called a property
property - properties tell us about the object
- if a function is part of an object it is called a method
method - Methods reresent tasks that are associated with an object
key - properties and methods have a name and value that is called a key
the value of a property can be a string, boolean, and array , or another object.
the value of a method is always a function
Creating an Object
Literal notaion is the easiest and most popular way to create objects
- the object is the curly braces and their content
-seperate each key from its value by using a colon
- seperate each property and method with a comma. (but not after the last value)
- use the
this
keyword to tell the method you are using the properties of this object
Acessing an object and DOT notation
- you can access the properties or methods of an object using dot notation
- you can also access properties using square brackets
- to access a property or method of an object you use the name of the object followed by a period
- then the name of the property or method you want to access
Dom
-
Document Object Model
- when a browser loads a page it creates a model
- the model is called a DOM tree
- it has different nodes
The Document Node
- when you access any element or attribute or text it has to go through the document node
Element Node
to access the dom tree you start by looking at elements
- once you find the elements you want then you access all other nodes if you want