My face still hurts a bit. I tried this moisturizer sample that has hyaluronic acid. Which is a substance that your skin already produces. So it should be fine, right? Wrong. My face and neck have red blotches on them. My face is getting much better but my neck is taking a while to get better. I should have spot tested the product out on my wrist first. But I have done that before and my face would still break out. I went back to using Ponds, which is what I normally used. But I have been using it since I was a kid so I like trying out new products sometime. If it’s new I like to get a sample first to make sure it won’t make my face react. And many times, samples are free. I’m trying not to scratch my neck. It itches. I still haven’t found a new face wash. I’ve been using Kel’s facewash for the past few months. I don’t like how expensive the facewash I normally use is ($39. for 8oz). So I’m looking for a good facewash that is a bit more inexpensive.
Thinking of downsizing my hair routing. Stop using a few products that I don’t think are working. I’m also trying to not wash it so often cause that isn’t good for your hair. But I’ve been exercising a lot and it’s hard to not wash my hair frequently. So I’ve been rinsing out the sweat in my hair and that seems to be working. I’ve been washing every three days. Tommy is lucky. He uses one hair product and his hair is fine. If I did that my hair would be a frizzy mess.
Let’s see, Alexis has a play coming up in October. I’m excited to see her in a new play. Karissa bought herself an older version of the Iphone. She is quite happy with it. The only thing she was a little bummed about was that there is no ear bud jack on the phone. It’s bluetooth only and she doesn’t have any ear bud or headphones that is bluetooth. I told her to hook it up to her hearing aid. I think headphones would be best for her and not ear buds. She can only use her right ear since her left is deaf.
We went to the Renaissance fair on Sunday. I liked some of the booths they had. It was a small fair. We weren’t there all day. The only downside was the blaring sun. I like the sun but I have a hard time being in the sun for long periods of time. The weather app betrayed us. It said it was going to be cloudy that day but it wasn’t. At least it wasn’t too hot outside.
I worked on the computer today. I like object oriented programming. I can understand a bit more easily. Still doing javaScript, but working with objects.
JavaScript notes…
—————————————-
The Bird and Dog constructors from the last challenge worked well. However, notice that all Birds that are created with the Bird constructor are automatically named Albert, are blue in color, and have two legs. What if you want birds with different values for name and color? It’s possible to change the properties of each bird manually but that would be a lot of work:
let swan = new Bird(); swan.name = "Carlos"; swan.color = "white";
Suppose you were writing a program to keep track of hundreds or even thousands of different birds in an aviary. It would take a lot of time to create all the birds, then change the properties to different values for every one. To more easily create different Bird objects, you can design your Bird constructor to accept parameters:
function Bird(name, color) { this.name = name; this.color = color; this.numLegs = 2; }
Then pass in the values as arguments to define each unique bird into the Bird constructor: let cardinal = new Bird(“Bruce”, “red”); This gives a new instance of Bird with name and color properties set to Bruce and red, respectively. The numLegs property is still set to 2. The cardinal has these properties:
cardinal.name cardinal.color cardinal.numLegs
The constructor is more flexible. It’s now possible to define the properties for each Bird at the time it is created, which is one way that JavaScript constructors are so useful. They group objects together based on shared characteristics and behavior and define a blueprint that automates their creation.
Create another Dog constructor. This time, set it up to take the parameters name and color, and have the property numLegs fixed at 4. Then create a new Dog saved in a variable terrier. Pass it two strings as arguments for the name and color properties.
function Dog(name, color) { this.name = name; this.color = color; this.numLegs = 4; } let terrier = new Dog("Mimi", "black");
Anytime a constructor function creates a new object, that object is said to be an instance of its constructor. JavaScript gives a convenient way to verify this with the instanceof operator. instanceof allows you to compare an object to a constructor, returning true or false based on whether or not that object was created with the constructor. Here’s an example:
let Bird = function(name, color) { this.name = name; this.color = color; this.numLegs = 2; } let crow = new Bird("Alexis", "black"); crow instanceof Bird;
This instanceof method would return true.
If an object is created without using a constructor, instanceof will verify that it is not an instance of that constructor:
let canary = { name: "Mildred", color: "Yellow", numLegs: 2 }; canary instanceof Bird;
This instanceof method would return false.
Create a new instance of the House constructor, calling it myHouse and passing a number of bedrooms. Then, use instanceof to verify that it is an instance of House.
function House(numBedrooms) { this.numBedrooms = numBedrooms; } // Only change code below this line let myHouse = new House(5); myHouse instanceof House;
In the following example, the Bird constructor defines two properties: name and numLegs:
function Bird(name) { this.name = name; this.numLegs = 2; } let duck = new Bird("Donald"); let canary = new Bird("Tweety");
name and numLegs are called own properties, because they are defined directly on the instance object. That means that duck and canary each has its own separate copy of these properties. In fact every instance of Bird will have its own copy of these properties. The following code adds all of the own properties of duck to the array ownProps:
let ownProps = []; for (let property in duck) { if(duck.hasOwnProperty(property)) { ownProps.push(property); } } console.log(ownProps);
The console would display the value [“name”, “numLegs”].
Add the own properties of canary to the array ownProps.
function Bird(name) { this.name = name; this.numLegs = 2; } let canary = new Bird("Tweety"); let ownProps = []; // Only change code below this line
function Bird(name) { this.name = name; this.numLegs = 2; } let canary = new Bird("Tweety"); let ownProps = []; // Only change code below this line for (let property in canary) { if(canary.hasOwnProperty(property)) { ownProps.push(property); } }
Since numLegs will probably have the same value for all instances of Bird, you essentially have a duplicated variable numLegs inside each Bird instance.
This may not be an issue when there are only two instances, but imagine if there are millions of instances. That would be a lot of duplicated variables.
A better way is to use the prototype of Bird. Properties in the prototype are shared among ALL instances of Bird. Here’s how to add numLegs to the Bird prototype:
Bird.prototype.numLegs = 2;
Now all instances of Bird have the numLegs property.
console.log(duck.numLegs); console.log(canary.numLegs);
Since all instances automatically have the properties on the prototype, think of a prototype as a “recipe” for creating objects. Note that the prototype for duck and canary is part of the Bird constructor as Bird.prototype.
Add a numLegs property to the prototype of Dog.
function Dog(name) { this.name = name; } // Only change code above this line let beagle = new Dog("Snoopy");
function Dog(name) { this.name = name; } Dog.prototype.numLegs = 4; // Only change code above this line let beagle = new Dog("Snoopy");
You have now seen two kinds of properties: own properties and prototype properties. Own properties are defined directly on the object instance itself. And prototype properties are defined on the prototype.
function Bird(name) { this.name = name; //own property } Bird.prototype.numLegs = 2; // prototype property let duck = new Bird("Donald");
Here is how you add duck’s own properties to the array ownProps and prototype properties to the array prototypeProps:
let ownProps = []; let prototypeProps = []; for (let property in duck) { if(duck.hasOwnProperty(property)) { ownProps.push(property); } else { prototypeProps.push(property); } } console.log(ownProps); console.log(prototypeProps);
console.log(ownProps) would display [“name”] in the console, and console.log(prototypeProps) would display [“numLegs”].
Add all of the own properties of beagle to the array ownProps. Add all of the prototype properties of Dog to the array prototypeProps.
function Dog(name) { this.name = name; } Dog.prototype.numLegs = 4; let beagle = new Dog("Snoopy"); let ownProps = []; let prototypeProps = []; // Only change code below this line
function Dog(name) { this.name = name; } Dog.prototype.numLegs = 4; let beagle = new Dog("Snoopy"); let ownProps = []; let prototypeProps = []; // Only change code below this line for (let property in beagle) { if(beagle.hasOwnProperty(property)) { ownProps.push(property); } else { prototypeProps.push(property); } }
There is a special constructor property located on the object instances duck and beagle that were created in the previous challenges:
let duck = new Bird(); let beagle = new Dog(); console.log(duck.constructor === Bird); console.log(beagle.constructor === Dog);
Both of these console.log calls would display true in the console.
Note that the constructor property is a reference to the constructor function that created the instance. The advantage of the constructor property is that it’s possible to check for this property to find out what kind of object it is. Here’s an example of how this could be used:
function joinBirdFraternity(candidate) { if (candidate.constructor === Bird) { return true; } else { return false; } }
Note: Since the constructor property can be overwritten (which will be covered in the next two challenges) it’s generally better to use the instanceof method to check the type of an object.
Write a joinDogFraternity function that takes a candidate parameter and, using the constructor property, return true if the candidate is a Dog, otherwise return false.
function Dog(name) { this.name = name; } // Only change code below this line function joinDogFraternity(candidate) { }
function Dog(name) { this.name = name; } // Only change code below this line function joinDogFraternity(candidate) { if (candidate.constructor === Dog) { return true; } else { return false; } }