Skip to content

Commit 7bc9f67

Browse files
author
David Brady
committed
Renamed 'Objects' chapter to 'Classes and Objects'; added class-variables recipes
1 parent 2619e15 commit 7bc9f67

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
layout: recipe
3+
title: Class Variables
4+
chapter: Classes and Objects
5+
---
6+
7+
h2. Creating Class Variables
8+
9+
You want to create a class variable.
10+
11+
h2. Solution
12+
13+
Use json notation in the class body; use :: to access it outside:
14+
15+
{% highlight coffeescript %}
16+
class Zoo
17+
MAX_ANIMALS: 50
18+
19+
Zoo::MAX_ZOOKEEPERS = 5
20+
21+
Zoo::MAX_ANIMALS
22+
# => 50
23+
{% endhighlight %}
24+
25+
h2. Discussion
26+
27+
Coffeescript will store these values on the class prototype (e.g. Zoo.prototype.MAX_ANIMALS) rather than on individual object instances, which conserves memory and gives a central location to store class-level values.

chapters/objects/cloning.textile renamed to chapters/classes_and_objects/cloning.textile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: recipe
33
title: Cloning an object (deep copy)
4-
chapter: Objects
4+
chapter: Classes and Objects
55
---
66

77
h2. Problem

chapters/objects/create-object-literal-if-not-exist.textile renamed to chapters/classes_and_objects/create-object-literal-if-not-exist.textile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: recipe
33
title: Create an object literal if it does not already exist
4-
chapter: Objects
4+
chapter: Classes and Objects
55
---
66

77
h2. Problem

chapters/objects/index.textile renamed to chapters/classes_and_objects/index.textile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: chapter
3-
title: Objects
4-
chapter: Objects
3+
title: Classes and Objects
4+
chapter: Classes and Objects
55
---
66

77
{% capture url %}/chapters/{{ page.chapter | replace: ' ', '_' | downcase }}{% endcapture %}

chapters/index.textile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ layout: default
33
title: Cookbook
44
chapters:
55
- Syntax
6-
- Objects
6+
- Classes and Objects
77
- Strings
88
- Arrays
99
- Dates and Times

0 commit comments

Comments
 (0)