L I V E S C R I P T
( O R / [ C O F F E E ] | [ L I V E ] S C R I P T / G )
R O C K I N G Y O U R W O R L D . J S
Copyrigh...
J S = F T W & & W T F
Type coercion strangely-ness
[1,2,3] + [5,6,7] = “1,2,35,6,7”
{} + [] = “[object Object]”
{} - [] = NaN
> typeof NaN
> ?
var x = 500
vs.
x = 500
for (x in [3,4,5]) {
console.log(x);
}
for (x in {1:2,3:4}) {
console.log(x);
}
Q U I Z
Which of the following is NOT a usable
javascript keyword:
a. var
b. with
c. in
d. class
e. undefined
JavaScript keywords:
break, case, catch, continue, debugger, default, delete, do, else,
false, finally, for, function, if,...
S P O T T H E B U G !
var car = {
state: "off",
start: function() {
this.state = "starting";
setTimeout(function() {
this....
P R O T O T Y P A L O O S T Y L E
var Person = function(name) {
return {
name: name,
getname: function() {
return this.nam...
null !== undefined
[coffee|live|type]script
A W H I R L A R O U N D C O F F E E
S C R I P T
syntax
scope
variables
functions
templating
list comp.
== vs. ===
lsc ~= coffee + x
F A T T Y G O O D N E S S
fix coffee’s weirdly-ness (like ‘=‘and list comps)
spicy curry and nice
ninja |> <| >> << operat...
LiveScript &lt;| Rocking your world.js
LiveScript &lt;| Rocking your world.js
Upcoming SlideShare
Loading in …5
×

LiveScript &lt;| Rocking your world.js

708 views

Published on

Company techsession around LiveScript, and the benefits of langs like Coffee and Live over Javascript directly

Published in: Software, Technology, Sports
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
708
On SlideShare
0
From Embeds
0
Number of Embeds
228
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • For recreating highlighted code:
    brew install highlight
    cat wtf.js | highlight --syntax=js --style clarity -O rtf | pbcopy
  • It’s everywhere - every single computer in the world runs at least a couple JS interpreters
    It’s multi-paradigm: OO, functional, dynamic, asynchronous
    It’s equally loved and hated by developers everywhere
    But it’s massively WTF too - lots of crazy stuff in there
  • It’s everywhere - every single computer in the world runs at least a couple JS interpreters
    It’s multi-paradigm: OO, functional, dynamic, asynchronous
    It’s equally loved and hated by developers everywhere
    But it’s massively WTF too - lots of crazy stuff in there
  • But whatever - they do actually follow a fairly reasonable convention, just sometimes a bit surprising
  • The evil “with” keyword:
    with (z) {
    y = 10; // good luck knowing if z.y or global y is being set
    }
  • Confusion and badly used generally
    “undefined” meaning the absence of a definition (similar to void)
    “null” meaning defined, but set to the absence of a value (similar to null)
    “==“ operator coercing null to undefined and vice versa, munging their meanings, whereas “===“ works as a better equality operator in most cases
  • Silver bullet languages! Fix all js issues!
    Except Typescript, which fixes a whole class of “issues” that don’t exist :)
  • var issues (coffeescript has to keep track of variables)
    do a class example with using -> and => bound functions
  • fixed scoping issue, use := to assign to the global
  • LiveScript &lt;| Rocking your world.js

    1. 1. L I V E S C R I P T ( O R / [ C O F F E E ] | [ L I V E ] S C R I P T / G ) R O C K I N G Y O U R W O R L D . J S Copyright 2014 - Synthesis Software Technology http://www.synthesis.co.za
    2. 2. J S = F T W & & W T F
    3. 3. Type coercion strangely-ness [1,2,3] + [5,6,7] = “1,2,35,6,7” {} + [] = “[object Object]” {} - [] = NaN
    4. 4. > typeof NaN > ?
    5. 5. var x = 500 vs. x = 500
    6. 6. for (x in [3,4,5]) { console.log(x); }
    7. 7. for (x in {1:2,3:4}) { console.log(x); }
    8. 8. Q U I Z Which of the following is NOT a usable javascript keyword: a. var b. with c. in d. class e. undefined
    9. 9. JavaScript keywords: break, case, catch, continue, debugger, default, delete, do, else, false, finally, for, function, if, in, instanceof, new, null, return, switch, this, throw, true, try, typeof, var, void, while, with. Reserved for future use: abstract, boolean, byte, char, class, const, double, enum, export, extends, final, float, goto, implements, import, int, interface, let, long, native, package, private, protected, public, short, static, super, synchronized, throws, transient, volatile, yield. Reserved for browser: alert, blur, closed, document, focus, frames, history, innerHeight, innerWidth, length, location, navigator, open, outerHeight, outerWidth, parent, screen, screenX, screenY, statusbar, window.
    10. 10. S P O T T H E B U G ! var car = { state: "off", start: function() { this.state = "starting"; setTimeout(function() { this.state = "started" }, 1000); } }; car.start();
    11. 11. P R O T O T Y P A L O O S T Y L E var Person = function(name) { return { name: name, getname: function() { return this.name.toUpperCase(); } } } var peter = new Person("Peter"); peter.getname(); var luke = { name: “Luke” }; luke.getname = peter.getname; luke.getname(); var crazy = peter.getname; crazy(); // ??
    12. 12. null !== undefined
    13. 13. [coffee|live|type]script
    14. 14. A W H I R L A R O U N D C O F F E E S C R I P T syntax scope variables functions templating list comp. == vs. ===
    15. 15. lsc ~= coffee + x
    16. 16. F A T T Y G O O D N E S S fix coffee’s weirdly-ness (like ‘=‘and list comps) spicy curry and nice ninja |> <| >> << operators async backcalls A N D B A T T E R I E S ! prelude more scary compiled js could be a gateway drug… >:-0 D O W N S I D E S O V E R C O F F E E ?

    ×