Skip to content

Commit

Permalink
Classes
Browse files Browse the repository at this point in the history
  • Loading branch information
mlynch committed Apr 25, 2015
1 parent b4bd23b commit 4e01fa1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions es6/classes/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ ES6 Classes will feel very natural for those with experience writing Object-Orie

```javascript
class Beer {
sell(location) {
}
}

class SpottedCow extends Beer {
Expand All @@ -17,6 +19,11 @@ class SpottedCow extends Beer {
this.locations = 'Wisconsin';
this.name = 'Spotted Cow';
}
sell(location) {
if(location !== 'Wisconsin') {
throw new JailTimeError();
}
}
}

class MillerLite extends Beer {
Expand All @@ -25,9 +32,18 @@ class MillerLite extends Beer {
this.locations = 'anywhere';
this.name = 'Miller Lite';
}
sell(location) {
if(Location.hasSportsTeam(location)) {
return true;
}
// Enh, we'll sell anywhere
return true;
}
}

let beer = new SpottedCow();

console.log('I am drinking a delicious', beer.name, 'that is available', beer.location);

beer.sell();
```

0 comments on commit 4e01fa1

Please sign in to comment.