Domain Modeling - process of creating a model in code for a problem.
The constructor function is a function that can be used to create an object model and then construct new objects based off of that model by passing in values for the pre-defined properties.
- Example:
const EpicFailVideo = function(epicRating, hasAnimals) { this.epicRating = epicRating; this.hasAnimals = hasAnimals; } let parkourFail = new EpicFailVideo(7, false); let corgiFail = new EpicFailVideo(4, true);
The example above intiates two new EpicFailVideo objects with the assoicated epicRating, and has Animals boolean, by using the new keyword.
Object prototypes can be used as doubles for objects to call methods. If a function isn't directly in an object is searched its prototypes next.
- this takes longer
- this is JS best practice
- when a prototype is shared between more than one object, it uses less memory
Tips (from resource above):
- When modeling a single entity that'll have many instances, build self-contained objects with the same attributes and behaviors.
- Model its attributes with a constructor function that defines and initializes properties.
- Model its behaviors with small methods that focus on doing one job well.
- Create instances using the new keyword followed by a call to a constructor function.
- Store the newly created object in a variable so you can access its properties and methods from outside.
- Use the this variable within methods so you can access the object's properties and methods from inside
Tables are great for displaying information in a grid...
List of Table Commands:
<table>- element used to create a table<tr>- represents each row (contained in<table>)<td>- represents each cell (contained in<tr>)<th>- table heading (contained in<tr>) think data labels,- use empty
<th>or<td>elements to represent blank cells when needed - attribute colspan="num_col" inside of
<td>element to create data that spans more than one column - attribute rowspan="num_row" inside of
<td>element to create data that spans more than one row <thead>- semantic heading of the table, will contain<th>elements, think top data labels<tbody>- semantic body of the table, think containing main data<tfoot>- semantic footer of the table, think containing summary data like total- use the 3 above with long tables
New Keyword:
- can be used to intialize new objects
const object_name = new Object ();- add properties using dot notation
object_name.property_name = value;object_name['property_name'] = value;- both notations above work the same
Delete Keyword:
- delete a property from an object
delete object_name.property_name;
Constructor Objects:
- see page 108 in book, also reference Domain Modeling reading above
- create several objects to represent similar things
- use a function as a template
- each parameter or arugment of the function represents a desired property for the object
- new objects are then created using the template function and passing in values to each parameter
- use new keyword
this Keyword:
- represents the object it is called in
Arrays are objects that use an index as it's key vs a property.
Built-in Objects - 3 Groups:
- Browser Object Model - model of the browser tab or window
- Document Object Model - model of current web page
- Global JavaScript Objects - not a single model, language related