Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

“Modern”

Slide 3

Slide 3 text

Tim Griesser @tgriesser

Slide 4

Slide 4 text

Tim Griesser @tgriesser

Slide 5

Slide 5 text

Tim Griesser @tgriesser

Slide 6

Slide 6 text

Tim Griesser @tgriesser

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

? ? ? ? ? ?

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

… but if it’s just JavaScript …

Slide 14

Slide 14 text

Single Page Web Apps

Slide 15

Slide 15 text

Single Page Web Apps

Slide 16

Slide 16 text

SPA Architecture

Slide 17

Slide 17 text

SPA Architecture Routes

Slide 18

Slide 18 text

SPA Architecture REST Routes

Slide 19

Slide 19 text

SPA Architecture SOLID REST Routes

Slide 20

Slide 20 text

SPA Architecture SOLID Services REST Routes

Slide 21

Slide 21 text

SPA Architecture SOLID Services REST Routes

Slide 22

Slide 22 text

SPA Architecture SOLID Services REST Routes

Slide 23

Slide 23 text

SPA Architecture SOLID Services REST Routes A mess of jQuery

Slide 24

Slide 24 text

SPA Architecture SOLID Services REST Routes A mess of jQuery

Slide 25

Slide 25 text

SPA Architecture SOLID Services REST Routes A mess of jQuery and javascript

Slide 26

Slide 26 text

SPA Architecture SOLID Services REST Routes A̩̱̞ ̥͈͓̱͇̫̗ m͎ e̶̠̻s̨s͙̖ ̵͍͈̖ o͙͚̫͙͖̯ͅ f̧̤ͅ ̯ j̨̩͔͓̠͎ Q̜u̳̞é̫͇r̮̙y̼̩̘̤͕̕ͅ ̖̩̦ ̹̺͚ ̹ ̰ ̱a̴̟n ͜ d ̪͜ ̘͓͍ j̷̗̦ a͟ ͈̙̗ v̙͖ͅ a̹̤̦s̵̹̙̱̘ c͏̰̱͖r͕͍͇̤̻̣ i ̯̩̹̮̻ p̮͖̤̭ t̻̭͓̫ ̩̬̙͜

Slide 27

Slide 27 text

SPA Architecture

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

What is wrong with these JS people?

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

JavaScript can be incredibly subjective

Slide 40

Slide 40 text

JavaScript can be incredibly flexible

Slide 41

Slide 41 text

Frameworks

Slide 42

Slide 42 text

• Library, not a framework. 6.5k (min/gzip) ! • Minimal Set of data-structuring (models, collections) and UI (views, urls) primitives for web applications ! • Very opinionated regarding REST-ful Models & Syncing ! • Not-so-much on Views, UI, Project Structure ! • Awesome “real world apps” list

Slide 43

Slide 43 text

• Framework for Building “Ambitious Web Applications” ! • Most similar to Laravel, batteries included approach making decisions for you, so you’re left implementing what makes your app different ! • More of a community ! • Larger footprint (71k min/gzip)

Slide 44

Slide 44 text

• HTML, “enhanced” for modern browsers ! • Inline declarations in HTML, encapsulating style & behavior in custom elements (directives) ! • Dependency Injection / Inversion of Control, Promises ! • Lots of resources, quickly gaining momentum ! • 2.0 will be more “Web Component” based

Slide 45

Slide 45 text

• Focus on Immutability: state is the root of all evil in web applications ! • JSX (compile to javascript HTML) ! • Virtual DOM ! • Comparable to angular, less conceptual overhead ! • Production use by Facebook, Instagram

Slide 46

Slide 46 text

17,938 10,143 23,641 6,302

Slide 47

Slide 47 text

17,938 10,143 23,641 6,302 Which should I use?

Slide 48

Slide 48 text

17,938 10,143 23,641 6,302 Which should I use? (drumroll)

Slide 49

Slide 49 text

…it doesn’t matter

Slide 50

Slide 50 text

1. Debugging Javascript 2. “this” 3. Other practical tips “The Rest of the Talk”

Slide 51

Slide 51 text

Alert Driven Development

Slide 52

Slide 52 text

console.log()

Slide 53

Slide 53 text

console.dir()

Slide 54

Slide 54 text

console.error() console.log + stack trace

Slide 55

Slide 55 text

debugger

Slide 56

Slide 56 text

breakpoint debugging

Slide 57

Slide 57 text

live editing

Slide 58

Slide 58 text

Backbone Debugger

Slide 59

Slide 59 text

Ember Debugger

Slide 60

Slide 60 text

Angular Debugger

Slide 61

Slide 61 text

React Debugger

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

https://developer.chrome.com/devtools/docs/authoring-development-workflow https://developers.google.com/chrome-developer-tools/docs/tips-and-tricks

Slide 64

Slide 64 text

this

Slide 65

Slide 65 text

$(this)

Slide 66

Slide 66 text

this === context

Slide 67

Slide 67 text

“left of the dot” user.sayName() / / this === user user.friends.add() / / this === user.friends console.log('Hi.') / / this === console someFunction() / / global

Slide 68

Slide 68 text

“left of the dot” Passing a function as an argument loses its value of "this" user.create(name, callback);

Slide 69

Slide 69 text

“left of the dot” user.create("Snappy", user.greet);

Slide 70

Slide 70 text

“left of the dot” user.create("Snappy", usergreet);

Slide 71

Slide 71 text

“left of the dot” user.create("Snappy", function() { user.greet(); });

Slide 72

Slide 72 text

“left of the dot”

Slide 73

Slide 73 text

…except when it’s not fn.bind(context) fn.call(context, arg1, arg2…) fn.apply(context, [array || arguments])

Slide 74

Slide 74 text

arguments fn.apply fn.call call_user_func_array() func_get_args() call_user_func()

Slide 75

Slide 75 text

When would I ever use this?

Slide 76

Slide 76 text

Inheritance

Slide 77

Slide 77 text

Monkey-Patching

Slide 78

Slide 78 text

JavaScript Is Very Object Oriented

Slide 79

Slide 79 text

JavaScript Is Confusingly Object Oriented, with Prototypes

Slide 80

Slide 80 text

$.fn

Slide 81

Slide 81 text

$.fn === $.prototype

Slide 82

Slide 82 text

functions are constructors var  User  =  function(name)  {      this.name  =  name;   };   User.prototype.sayName  =  function()  {      alert("Hello  "  +  this.name);   };   ! var  user  =  new  User("Tim");

Slide 83

Slide 83 text

functions are constructors class  User  {   !    public  function  __construct($name)  {          $this-­‐>name  =  $name;      }   !    public  function  sayName()  {          echo("Hello  "  .  $this-­‐>name);      }   }   ! var  user  =  new  User("Tim");

Slide 84

Slide 84 text

“I can write OO code similar to PHP”

Slide 85

Slide 85 text

functions are also objects User.name  =  "Not  Tim";   ! console.log(User.name)  //  "Not  Tim"   ! var  user  =  new  User("Tim");   ! console.log(user.name)  //  "Tim"

Slide 86

Slide 86 text

If you’re ever confused about what’s what… ! Remember: Just throw a debugger in there and take a look around

Slide 87

Slide 87 text

Additional Practical Tips

Slide 88

Slide 88 text

Arrays are Objects, Objects are References

Slide 89

Slide 89 text

var  x  =  {};  

Slide 90

Slide 90 text

var  x  =  {};   $x        =  [];

Slide 91

Slide 91 text

var  x  =  {};   $x        =  [];

Slide 92

Slide 92 text

$x  =  new  StdClass();

Slide 93

Slide 93 text

No content

Slide 94

Slide 94 text

No content

Slide 95

Slide 95 text

No content

Slide 96

Slide 96 text

No content

Slide 97

Slide 97 text

var  User  =  function(name)  {      this.name  =  name;   };   ! User.prototype.nicknames  =  [];   ! User.prototype.sayName  =  function()  {      alert("Hello  "  +  this.name);   };   !

Slide 98

Slide 98 text

var  user  =  new  User("Timothy");   ! user.nicknames.push("Tim");   ! console.log(user.nicknames);  //  ['Tim']  

Slide 99

Slide 99 text

var  user  =  new  User("Timothy");   ! user.nicknames.push("Tim");   ! console.log(user.nicknames);  //  ['Tim']   ! var  otherUser  =  new  User("Joseph");   ! otherUser.nicknames.push("Joe");   ! console.log(otherUser.nicknames);  //  ['Tim',  'Joe']

Slide 100

Slide 100 text

var  Account  =  Ember.Object.extend({      users:  []   }); var  Account  =  Backbone.Model.extend({      users:  []   });

Slide 101

Slide 101 text

var  account  =  new  Account();   ! account.users.push('Name');   ! var  anotherAccount  =  new  Account();   ! anotherAccount.users  //  ['Name'];

Slide 102

Slide 102 text

Always create objects & arrays inside a constructor, almost never put them on a prototype ! Again, use the debugger!

Slide 103

Slide 103 text

Scopes, References, GC can be really confusing ! Again: use the debugger!

Slide 104

Slide 104 text

No content

Slide 105

Slide 105 text

No content

Slide 106

Slide 106 text

Avoid throwing JS in your view partials ! Single JS file, split up functionality based on URL MVC + JS

Slide 107

Slide 107 text

(not just for node)

Slide 108

Slide 108 text

“My Front-End Toolkit” /watchify

Slide 109

Slide 109 text

“My Front-End Toolkit” /watchify

Slide 110

Slide 110 text

No content

Slide 111

Slide 111 text

JavaScript, it’s not all terrible. ! The End ! @tgriesser

Slide 112

Slide 112 text

No content

Slide 113

Slide 113 text

Photos & Links • Links: • https://developer.chrome.com/devtools/docs/authoring-development-workflow • https://developers.google.com/chrome-developer-tools/docs/tips-and-tricks • http://superherojs.org • http://browserify.org/ • https://github.com/aaronlord/laroute • https://github.com/node-inspector/node-inspector • Photos: • https://www.flickr.com/photos/xjrlokix/8192703395/in/photostream/ • http://www.fastcolabs.com/3015764/sticker-styling-14-laptop-covers-from-tech-innovators