Skip to content

Commit

Permalink
switched tabs to spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorcorrea committed Jun 5, 2012
1 parent a452c55 commit 79827f4
Show file tree
Hide file tree
Showing 20 changed files with 165 additions and 167 deletions.
2 changes: 1 addition & 1 deletion 03_function.coffee
@@ -1,4 +1,4 @@
square = (x) ->
square = (x) ->
x * x

n = 9
Expand Down
6 changes: 3 additions & 3 deletions 07_existential.coffee
Expand Up @@ -2,9 +2,9 @@ billTo = {}
billTo.street = "111 Accounting St."
billTo.city = "State College"

shipTo = {}
shipTo.street = "222 Warehouse Blvd."
shipTo.city = "Bellefonte"
# shipTo = {}
# shipTo.street = "222 Warehouse Blvd."
# shipTo.city = "Bellefonte"

label = shipTo ? billTo
console.log "#{label.street}"
10 changes: 2 additions & 8 deletions 07_existential.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions 07_existentialchain.coffee
Expand Up @@ -6,12 +6,12 @@ shipTo = {}
shipTo.street = "222 Warehouse Bldv."
shipTo.city = "Bellefonte"
shipTo.attn =
name: "John Doe"
title: "Mr."
name: "John Doe"
title: "Mr."

city = shipTo?.city ? billTo.city
console.log "City: #{city}"
# city = shipTo?.city ? billTo.city
# console.log "City: #{city}"

# attn = shipTo?.attn?.name ? "N/A"
# console.log "Attn: #{attn}"
attn = shipTo?.attn?.name ? "N/A"
console.log "Attn: #{attn}"

6 changes: 3 additions & 3 deletions 07_existentialchain.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion 10_context.coffee
Expand Up @@ -7,7 +7,7 @@ $ ->
# Value of "this" if the jQuery XML HTTP Request (jqXHR) object
$('#btnTest2').click ->
url = "file:///Users/hector/dev/coffee/intro-to-coffeescript/10_context.txt"
$.get url, (data) ->
$.get url, (data) =>
alert this.value

# # Value of "this" is the DOM Window
Expand Down
5 changes: 3 additions & 2 deletions 10_context.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions 20_class.coffee
@@ -1,12 +1,12 @@
class TaxCalculator
tax = 0
tax = 0

constructor: (tax) ->
this.tax = tax
constructor: (tax) ->
this.tax = tax

taxAmount: (price) -> price * (this.tax/100)
taxAmount: (price) -> price * (this.tax/100)

totalPrice: (price) -> price + (price * (this.tax/100))
totalPrice: (price) -> price + (price * (this.tax/100))


calc = new TaxCalculator(20)
Expand Down
6 changes: 3 additions & 3 deletions 21_class_def_args_and_this.coffee
@@ -1,10 +1,10 @@
class TaxCalculator

constructor: (@tax = 10) ->
constructor: (@tax = 10) ->

taxAmount: (price) -> price * (@tax/100)
taxAmount: (price) -> price * (@tax/100)

totalPrice: (price) -> price + @taxAmount(price)
totalPrice: (price) -> price + @taxAmount(price)


calc = new TaxCalculator(30)
Expand Down
10 changes: 5 additions & 5 deletions 23_class_static_methods.coffee
@@ -1,13 +1,13 @@
class TaxCalculator

constructor: (@tax = 10) ->
constructor: (@tax = 10) ->

taxAmount: (price) -> price * (@tax/100)
taxAmount: (price) -> price * (@tax/100)

totalPrice: (price) -> price + @taxAmount(price)
totalPrice: (price) -> price + @taxAmount(price)

@isTaxableState: (state) ->
state in ['PA', 'MO', 'NY']
@isTaxableState: (state) ->
state in ['PA', 'MO', 'NY']

state = 'NY'
isTaxable = TaxCalculator.isTaxableState(state)
Expand Down
10 changes: 5 additions & 5 deletions 24_class_inheritance.coffee
@@ -1,17 +1,17 @@
class TaxCalculator

constructor: (@tax = 10) ->
constructor: (@tax = 10) ->

taxAmount: (price) -> price * (@tax/100)
taxAmount: (price) -> price * (@tax/100)

totalPrice: (price) -> price + @taxAmount(price)
totalPrice: (price) -> price + @taxAmount(price)


class MeanTaxCalculator extends TaxCalculator

totalPrice: (price) -> price + @taxAmount(price) + 25
totalPrice: (price) -> price + @taxAmount(price) + 25

anotherMethod: -> "hello"
anotherMethod: -> "hello"

calc = new MeanTaxCalculator()
total = calc.totalPrice(500)
Expand Down
20 changes: 10 additions & 10 deletions 25_class_context.coffee
@@ -1,18 +1,18 @@
class InvoiceForm

constructor: (@customer) ->
constructor: (@customer) ->

# Value of "this" might not be the InvoiceForm class
calculateTotal: ->
# do some fancy calculation
total = 10
alert "#{this.customer} your total is #{total}"
# Value of "this" might not be the InvoiceForm class
calculateTotal: =>
# do some fancy calculation
total = 10
alert "#{this.customer} your total is #{total}"

$ ->
invoice = new InvoiceForm("Acme Corporation")
invoice.calculateTotal()
$('#btnCalculate').click invoice.calculateTotal
invoice = new InvoiceForm("Acme Corporation")
invoice.calculateTotal()
$('#btnCalculate').click invoice.calculateTotal


# If you look at the JavaScript code generated, the
Expand Down
5 changes: 4 additions & 1 deletion 25_class_context.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions 31_destructuring_object.coffee
Expand Up @@ -3,12 +3,12 @@

fetchCustomer = (id) ->
# Make an Ajax request to fetch the customer data...
customer =
name: "Acme Corporation"
address: "123 desert"
attention: "Wile E. Coyote"
email: "wile@acme.com"
customer
customer =
name: "Acme Corporation"
address: "123 desert"
attention: "Wile E. Coyote"
email: "wile@acme.com"
customer

{name, address} = fetchCustomer(1)
console.log "#{name}: #{address}"
6 changes: 3 additions & 3 deletions 32_loops.coffee
Expand Up @@ -10,16 +10,16 @@ colors = ['red', 'blue', 'white']

console.log "Sample 1 (loop) ------------"
for color in colors
console.log color
console.log color


console.log "\r\nSample 2 (loop with i) ------------"
for color, i in colors
console.log i, color
console.log i, color


console.log "\r\nSample 3 (comprehension) ------------"
# toUpper = (value) -> value.toUpperCase()
#toUpper = (value) -> value.toUpperCase()

upper = (c.toUpperCase() for c in colors)
console.log upper
Expand Down
14 changes: 7 additions & 7 deletions 33_loops_jquery.coffee
@@ -1,10 +1,10 @@
$ ->

$("#btnSave").click ->
for r in $(".required")
if $(r).val() is ""
$(r).addClass("missing")
else
$(r).removeClass("missing")
$("#btnSave").click ->
for r in $(".required")
if $(r).val() is ""
$(r).addClass("missing")
else
$(r).removeClass("missing")

return
return
24 changes: 12 additions & 12 deletions js_primer/closure_fade.html
Expand Up @@ -12,23 +12,23 @@
by Douglas Crockford p. 38
-->
<body>
<h1>Fade Color Example</h1>
<p>Count: <span id="counter"/></p>

<script type="text/javascript">
var fade = function(node, node2) {
var level = 1;
var step = function () {
var hex = level.toString(16);
node.style.backgroundColor = 'FFFF' + hex + hex;
node2.innerText = level.toString();
if(level < 15) {
level += 1;
setTimeout(step, 300);
}
};
setTimeout(step,300);
var level = 1;
var step = function () {
var hex = level.toString(16);
node.style.backgroundColor = 'FFFF' + hex + hex;
node2.innerText = level.toString();
if(level < 15) {
level += 1;
setTimeout(step, 300);
}
};
setTimeout(step,300);
};

fade(document.body, document.getElementById("counter"));
Expand Down
48 changes: 24 additions & 24 deletions js_primer/func.html
Expand Up @@ -7,32 +7,32 @@
<h1>SaySomething</h2>
<script type="text/javascript">

// // From: The Little Book of CoffeeScript by Alex MacCaw p. 41
// if(true) {
// function saySomething() {
// return "first";
// }
// } else {
// function saySomething() {
// return "second";
// }
// }
//
// // FireFox returns first but Safari and Chrome return second
// alert( saySomething() );
// // From: The Little Book of CoffeeScript by Alex MacCaw p. 41
// if(true) {
// function saySomething() {
// return "first";
// }
// } else {
// function saySomething() {
// return "second";
// }
// }
//
// // FireFox returns first but Safari and Chrome return second
// alert( saySomething() );

if(true) {
var saySomething = function() {
return "first";
}
} else {
var saySomething = function() {
return "second";
}
}
if(true) {
var saySomething = function() {
return "first";
}
} else {
var saySomething = function() {
return "second";
}
}

// FireFox, Safari and Chrome return first
alert( saySomething() );
// FireFox, Safari and Chrome return first
alert( saySomething() );
</script>
</body>
</html>

0 comments on commit 79827f4

Please sign in to comment.