Skip to content

Commit

Permalink
fix tabs in code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsoe committed Dec 9, 2017
1 parent 1252808 commit 2eea483
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions 51 - Prototypal Inheritance Review.md
Expand Up @@ -5,10 +5,10 @@ What I wanted to do in this video is do a quick review of how prototypal inherit
What I want to do here is let's make a dog function that will create puppies or create many dogs:

```js
function Dog(name, breed) {
this.name = name;
this.breed = breed;
}
function Dog(name, breed) {
this.name = name;
this.breed = breed;
}
```
Notice we're using a capital D on `Dog` because this is what's called a constructor function. The function itself will pass in whatever we get for name and breed are assigned as `name`, and `breed`.

Expand Down Expand Up @@ -41,14 +41,14 @@ Where did they come from? Well, we have the "Mama array", which is capital A, `A
We're going to take a look at how they don't just take their own, they actually share the same one. Let's add a prototype method to our `Dog`:

```js
function Dog(name, breed) {
this.name = name;
this.breed = breed;
}
Dog.prototype.bark = function() {
console.log(`Bark Bark! My name is ${this.name}`);
}
const snickers = new Dog('Snickers', 'King Charles');
function Dog(name, breed) {
this.name = name;
this.breed = breed;
}
Dog.prototype.bark = function() {
console.log(`Bark Bark! My name is ${this.name}`);
}
const snickers = new Dog('Snickers', 'King Charles');
```

Remember, we're using template strings to call `this.name`, because we want to reference the name of the actual dog. If you run `snickers.bark()` in your console, it says, "Bark, bark. My name is Snickers." Makes sense.
Expand All @@ -63,26 +63,26 @@ If we run `sunny.bark()`, It returns "Bark, bark. My name is Sunny." You see how
What's really cool about that is you can still change it after the fact:

```js
function Dog(name, breed) {
this.name = name;
this.breed = breed;
}
Dog.prototype.bark = function() {
console.log(`Bark Bark! My name is ${this.name}`);
}
const snickers = new Dog('Snickers', 'King Charles');
const sunny = new Dog('Sunny', 'Golden Doodle');
Dog.prototype.bark = function() {
console.log(`Bark bark! my name is ${this.name} and I'm a ${this.breed}!`);
}
function Dog(name, breed) {
this.name = name;
this.breed = breed;
}
Dog.prototype.bark = function() {
console.log(`Bark Bark! My name is ${this.name}`);
}
const snickers = new Dog('Snickers', 'King Charles');
const sunny = new Dog('Sunny', 'Golden Doodle');

Dog.prototype.bark = function() {
console.log(`Bark bark! my name is ${this.name} and I'm a ${this.breed}!`);
}
```

Even though I've created `snickers` before I've added this method should it still do this? Absolutely. What if I added a second method onto it after the fact?

```js
Dog.prototype.cuddle = function() {
console.log(`I love you owner!`);
Dog.prototype.cuddle = function() {
console.log(`I love you owner!`);
}
```

Expand All @@ -92,4 +92,4 @@ If you just `snickers` in your console and you open it up and you won't see `bar

But `bark` and `cuddle` are on the prototype, which means that they're not part of the actual object, `snickers`. But if you open that it up, you'll see `bark` and `cuddle` are right inside of `__proto__` in your DevTools.

With that in mind, let's learn about how we can also do this sort of thing when we write classes.
With that in mind, let's learn about how we can also do this sort of thing when we write classes.

0 comments on commit 2eea483

Please sign in to comment.