abstract boolean break byte case catch char class const
continue debugger default delete do double else enum
export extends false final finally float for function
goto if implements import in instanceof int interface
long native new null package private protected public
return short static super switch synchronized this throw
throws transient true try typeof var volatile void while
with
Slide 29
Slide 29 text
abstract boolean break byte case catch char class const
continue debugger default delete do double else enum
export extends false final finally float for function
goto if implements import in instanceof int interface
long native new null package private protected public
return short static super switch synchronized this throw
throws transient true try typeof var volatile void while
with
Slide 30
Slide 30 text
No content
Slide 31
Slide 31 text
;
Slide 32
Slide 32 text
http://davidwalsh.name/javascript-semicolons
Slide 33
Slide 33 text
a = b + c
(d + e).print()
Slide 34
Slide 34 text
a = b + c(d + e).print();
Slide 35
Slide 35 text
function add() {
var a = 1, b = 2
return
a + b
}
Slide 36
Slide 36 text
function add() {
var a = 1, b = 2;
return;
a + b;
}
Slide 37
Slide 37 text
No content
Slide 38
Slide 38 text
“Expose the good parts of
JavaScript in a simple way”
Slide 39
Slide 39 text
<>
Slide 40
Slide 40 text
.js
<>
Slide 41
Slide 41 text
<>
Slide 42
Slide 42 text
<>
Slide 43
Slide 43 text
.js
<>
Slide 44
Slide 44 text
.js
.coffee
Slide 45
Slide 45 text
.js
.coffee
Slide 46
Slide 46 text
.js
.coffee
Slide 47
Slide 47 text
Compiler
Slide 48
Slide 48 text
.js
.coffee
.litcoffee
Slide 49
Slide 49 text
.js
.coffee
.litcoffee
Slide 50
Slide 50 text
Publish via rsync
-----------------
Publishing is nice and rudimentary. We build out an entirely static version
of the site and **rysnc** it up to the server.
Journo.publish = ->
do Journo.build
rsync 'site/images/', path.join(shared.config.publish, 'images/'), ->
rsync 'site/', shared.config.publish
A helper function for **rsync**ing, with logging, and the ability to wait
for the rsync to continue before proceeding. This is useful for ensuring
that our any new photos have finished uploading (very slowly) before the
update to the feed
is syndicated out.
https://github.com/jashkenas/journo/blob/master/journo.litcoffee
greeting = "#{30 - user.age} years until 30!"
var greeting;
greeting = "" + (30 - user.age) + " years until 30!";
Slide 119
Slide 119 text
age = 27
ageString = "#{age}"
var age, ageString;
age = 27;
ageString = "" + age;
Slide 120
Slide 120 text
Multiline strings
Slide 121
Slide 121 text
story = "Some people go batshit crazy
if your code exceeds 80 columns per
line so yo better just don't do."
var story;
story = "Some people go batshit crazy if your code ↵
execeds 80 columns per line so yo better just don't ↵
do.";
Slide 122
Slide 122 text
Block strings
Slide 123
Slide 123 text
headerMarkup = """
XML is like violence
"""
var headerMarkup;
headerMarkup = "\n
XML is like ↵
violence
\n";
Slide 124
Slide 124 text
Regular expressions
Slide 125
Slide 125 text
mastercard = /5[1-5][0-9]{14}/
var mastercard;
mastercard = /^5[1-5][0-9]{14}$/;
Slide 126
Slide 126 text
mastercard = /// ^
5[1-5] # starts with 51..55
[0-9]{14} # 14 more digits
$ ///
var mastercard;
mastercard = /^5[1-5][0-9]{14}$/;
makeAdder = (x) -> (y) -> x + y
add5 = makeAdder(5)
add5(10) # => 15
var makeAdder;
makeAdder = function(x) {
return function(y) {
return x + y;
};
};
Slide 146
Slide 146 text
do ->
do (argument) ->
(function() {})();
(function(argument) {})(argument);
Slide 147
Slide 147 text
Conditionals
Slide 148
Slide 148 text
if name == 'John'
console.log "It's John again."
else if name == 'Marcy'
console.log "It's Marcy this time."
else
console.log "It's not John."
unless name == 'John'
console.log "It's someone else"
Slide 149
Slide 149 text
if (name === 'John') {
console.log("It's John again.");
} else if (name === 'Marcy') {
console.log("It's Marcy this time.");
} else {
console.log("It's not John.");
}
if (name !== 'John') {
console.log("It's someone else");
}
Slide 150
Slide 150 text
if name == 'John' then console.log "It's John again."
Slide 151
Slide 151 text
Postfix
Slide 152
Slide 152 text
console.log "It's John again." if name == 'John'
console.log "It's someone else" unless name == 'John'
Slide 153
Slide 153 text
Everything’s an expression
Slide 154
Slide 154 text
message = if name == 'John'
"It's John again."
else if name == 'Marcy'
"It's Marcy this time."
else
"It's not John."
console.log message
Slide 155
Slide 155 text
message =
if name == 'John' then "It's John again."
else if name == 'Marcy' then "It's Marcy this time."
else "It's not John."
console.log message
Slide 156
Slide 156 text
[lastName, age] =
if name == 'John' then ['Doe', 23]
else if name == 'Marcy' then ['Murcy', 29]
else ['Unknown' ]
console.log lastName, age
Slide 157
Slide 157 text
Ternary
Slide 158
Slide 158 text
var isJohn = name == 'John' ? 'yep' : 'nope';
Slide 159
Slide 159 text
isJohn = if name == 'John' then 'yep' else 'nope'
Slide 160
Slide 160 text
var isJohn;
isJohn = name === 'John' ? 'yep' : 'nope';
Slide 161
Slide 161 text
(›°□°ʣ›ớ ᵲᴸᵲ
Slide 162
Slide 162 text
“I realize its slightly longer, but
less cryptic, I hope.”
— Jeremy Ashkenas
Slide 163
Slide 163 text
Operators and aliases
Slide 164
Slide 164 text
isJohn = if name is 'John' then 'yep' else 'nope'
Slide 165
Slide 165 text
is ===
isnt !==
not !
and &&
or ||
true, yes, on true
false, no, off false
@, this this
of in
in
Slide 166
Slide 166 text
is ===
isnt !==
not !
and &&
or ||
true, yes, on true
false, no, off false
@, this this
of in
in
Slide 167
Slide 167 text
is ===
isnt !==
not !
and &&
or ||
true, yes, on true
false, no, off false
@, this this
of in
in
Slide 168
Slide 168 text
letIn() if name in ['John', 'Marcy']
Slide 169
Slide 169 text
letIn() if name in ['John', 'Marcy']
if (name === 'John' || name === 'Marcy') {
letIn();
}
Slide 170
Slide 170 text
Existential operator
Slide 171
Slide 171 text
invite(user) if user?
Slide 172
Slide 172 text
if (typeof user !== "undefined" && user !== null) {
invite(user);
}
Slide 173
Slide 173 text
name = userName ? 'John'
var name;
name = typeof userName !== "undefined" && ↵
userName !== null ? userName : 'John';
Slide 174
Slide 174 text
name = 'John'
name ?= 'Marcy'
var name;
name = 'John';
if (name == null) {
name = 'Marcy';
}
Slide 175
Slide 175 text
name = 'Marcy Murcy'
john = name.match(/John/)?[0]
var john, name, _ref;
name = 'Marcy Murcy';
john = (_ref = name.match(/John/)) != null ? ↵
_ref[0] : void 0;
var User;
User = (function() {
function User() {}
return User;
})();
Slide 201
Slide 201 text
Constructor
Slide 202
Slide 202 text
class User
constructor: (name) ->
@name = name
Slide 203
Slide 203 text
var User;
User = (function() {
function User(name) {
this.name = name;
}
return User;
})();
Slide 204
Slide 204 text
class User
constructor: (@name) ->
Slide 205
Slide 205 text
class User
constructor: (@name = 'Undefined') ->
Slide 206
Slide 206 text
Instance methods
Slide 207
Slide 207 text
class User
constructor: (@firstName, @lastName) ->
fullName: ->
"#{@firstName} #{@lastName}"
john = new User('John', 'Doe')
john.fullName()
# => "John Doe"
class User
constructor: (@name) ->
message: -> "Hello #{@name}!"
class Invitee extends User
message: ->
"#{super()} You are invited"
invitee = new Invitee 'John'
invitee.message()
# => "Hello John! You are invited"
Slide 225
Slide 225 text
Invitee.prototype.message = function() {
return "" + (Invitee.__super__.message.call(this)) ↵
+ " You are invited";
};