42
// hacking // javascript // complexity // @leJDen // Jason Denizac // CC-BY 3.0

Hacking JavaScript Complexity - Boise Code Camp 12

Embed Size (px)

DESCRIPTION

Video: (1'15") http://www.youtube.com/watch?v=Ea0FKq0a2-g&feature=youtu.be Materials: https://github.com/jasondenizac/bcc12 Given 3/24/2012 Boise State University

Citation preview

Page 1: Hacking JavaScript Complexity - Boise Code Camp 12

// hacking// javascript // complexity // @leJDen// Jason Denizac// CC-BY 3.0

Page 2: Hacking JavaScript Complexity - Boise Code Camp 12
Page 3: Hacking JavaScript Complexity - Boise Code Camp 12

disclaimer:

a lot of this is just my opinion, man.

Page 4: Hacking JavaScript Complexity - Boise Code Camp 12
Page 5: Hacking JavaScript Complexity - Boise Code Camp 12

me:

healthwise.org @boisehackers i <3 javascript

Page 6: Hacking JavaScript Complexity - Boise Code Camp 12

you:

beyond beginning javascript have ever thought...

There's gotta be a better way!

Page 7: Hacking JavaScript Complexity - Boise Code Camp 12
Page 8: Hacking JavaScript Complexity - Boise Code Camp 12

style modules testing

{ }

Page 9: Hacking JavaScript Complexity - Boise Code Camp 12
Page 10: Hacking JavaScript Complexity - Boise Code Camp 12

style { }

Page 11: Hacking JavaScript Complexity - Boise Code Camp 12

sanity. { }

Page 12: Hacking JavaScript Complexity - Boise Code Camp 12

{ }

Page 13: Hacking JavaScript Complexity - Boise Code Camp 12

== { }

Page 14: Hacking JavaScript Complexity - Boise Code Camp 12

==1. If Type(x) is the same as Type(y), then

a. If Type(x) is Undefined, return true.b. If Type(x) is Null, return true.c. If Type(x) is Number, then

i. If x is NaN, return false.ii. If y is NaN, return false.iii. If x is the same Number value as y, return true.iv. If x is +0 and y is −0, return true.v. If x is −0 and y is +0, return true.vi. Return false.

d. If Type(x) is String, then return true if x and y are exactly the same sequence of characters (same length and same characters in corresponding positions). Otherwise, return false.

e. If Type(x) is Boolean, return true if x and y are both true or both false. Otherwise, return false.f. Return true if x and y refer to the same object. Otherwise, return false.

2. If x is null and y is undefined, return true.3. If x is undefined and y is null, return true.4. If Type(x) is Number and Type(y) is String,5. return the result of the comparison x == ToNumber(y).6. If Type(x) is String and Type(y) is Number,7. return the result of the comparison ToNumber(x) == y.8. If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y.9. If Type(y) is Boolean, return the result of the comparison x == ToNumber(y).

10. If Type(x) is either String or Number and Type(y) is Object,11. return the result of the comparison x == ToPrimitive(y).12. If Type(x) is Object and Type(y) is either String or Number,13. return the result of the comparison ToPrimitive(x) == y.14. Return false.

{ }

Page 15: Hacking JavaScript Complexity - Boise Code Camp 12

==1. If Type(x) is the same as Type(y), then

a. If Type(x) is Undefined, return true.b. If Type(x) is Null, return true.c. If Type(x) is Number, then

i. If x is NaN, return false.ii. If y is NaN, return false.iii. If x is the same Number value as y, return true.iv. If x is +0 and y is −0, return true.v. If x is −0 and y is +0, return true.vi. Return false.

d. If Type(x) is String, then return true if x and y are exactly the same sequence of characters (same length and same characters in corresponding positions). Otherwise, return false.

e. If Type(x) is Boolean, return true if x and y are both true or both false. Otherwise, return false.f. Return true if x and y refer to the same object. Otherwise, return false.

2. If x is null and y is undefined, return true.3. If x is undefined and y is null, return true.4. If Type(x) is Number and Type(y) is String,5. return the result of the comparison x == ToNumber(y).6. If Type(x) is String and Type(y) is Number,7. return the result of the comparison ToNumber(x) == y.8. If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y.9. If Type(y) is Boolean, return the result of the comparison x == ToNumber(y).

10. If Type(x) is either String or Number and Type(y) is Object,11. return the result of the comparison x == ToPrimitive(y).12. If Type(x) is Object and Type(y) is either String or Number,13. return the result of the comparison ToPrimitive(x) == y.14. Return false.

"Wat?!"

{ }

*apologies to Gary Bernhardt

Page 16: Hacking JavaScript Complexity - Boise Code Camp 12

=== { }

Page 17: Hacking JavaScript Complexity - Boise Code Camp 12

===

1. Is it the same type?{ }

Page 18: Hacking JavaScript Complexity - Boise Code Camp 12

===

1. Is it the same type?2. Is the value the same?

{ }

Page 19: Hacking JavaScript Complexity - Boise Code Camp 12

===

1. Is it the same type?2. Is the value the same? * NaN !== NaN

{ }

Page 20: Hacking JavaScript Complexity - Boise Code Camp 12

{ }"Warning! JSLint will hurt your feelings."

Page 21: Hacking JavaScript Complexity - Boise Code Camp 12
Page 22: Hacking JavaScript Complexity - Boise Code Camp 12

modules

Page 23: Hacking JavaScript Complexity - Boise Code Camp 12
Page 24: Hacking JavaScript Complexity - Boise Code Camp 12

godObject.blah.foo.module godObject.blang.other.functionality godObject.something.More

Page 25: Hacking JavaScript Complexity - Boise Code Camp 12
Page 26: Hacking JavaScript Complexity - Boise Code Camp 12
Page 27: Hacking JavaScript Complexity - Boise Code Camp 12

A synchronousM oduleD efinition

Page 28: Hacking JavaScript Complexity - Boise Code Camp 12
Page 29: Hacking JavaScript Complexity - Boise Code Camp 12

define(['jquery'], function ($) {return function () {$('<strong/>').text('Ohh yeahh.jpg').appendTo('body');};

});

sugarWater.js

Page 30: Hacking JavaScript Complexity - Boise Code Camp 12

require(['jquery', 'sugarWater',

'domReady!'], function ($, ohhYeahh) {$('#refreshing').on('click', ohhYeahh);

});

main.js

Page 31: Hacking JavaScript Complexity - Boise Code Camp 12
Page 32: Hacking JavaScript Complexity - Boise Code Camp 12

require.js

Page 33: Hacking JavaScript Complexity - Boise Code Camp 12

microjs.com "there's a lib for that"

Page 34: Hacking JavaScript Complexity - Boise Code Camp 12
Page 35: Hacking JavaScript Complexity - Boise Code Camp 12

testing

Page 38: Hacking JavaScript Complexity - Boise Code Camp 12

sinon

Page 39: Hacking JavaScript Complexity - Boise Code Camp 12
Page 40: Hacking JavaScript Complexity - Boise Code Camp 12

DEMO TIME

Using TDD, JSLint, and modules,

make yet another Twitter search visualization

- show me a live stream of tweets with #bcc or @BoiseCodeCamp

- highlight presenters

Page 41: Hacking JavaScript Complexity - Boise Code Camp 12

other talks today:

Next: Travis Bretton: Server side: Node.jsright here

Later: @jarodf: Client side: Backbone.js

also right here, 4:30

Page 42: Hacking JavaScript Complexity - Boise Code Camp 12

get the code

github.com/jasondenizac/bcc12 @leJDen