34
Functional JavaScript Practical Tips, Tricks and Experiences @wolframkriesing @uxebu Montag, 16. November 2009

Functional Java Script - Webtechcon 2009

Embed Size (px)

DESCRIPTION

These slides (and the linked code samples) show some aspects of functional javascript programming.

Citation preview

Page 1: Functional Java Script - Webtechcon 2009

Functional JavaScriptPractical Tips, Tricks and Experiences

@wolframkriesing @uxebu

Montag, 16. November 2009

Page 2: Functional Java Script - Webtechcon 2009

Montag, 16. November 2009

Page 3: Functional Java Script - Webtechcon 2009

JavaScript AJAX

CSSdojo

Browser

OpenSourceWeb2.0FrontEnd

Usability

UserExperience

django

mobilewidgets

Montag, 16. November 2009

Page 4: Functional Java Script - Webtechcon 2009

What is Functional Programming?

Montag, 16. November 2009

Page 5: Functional Java Script - Webtechcon 2009

Montag, 16. November 2009

Page 8: Functional Java Script - Webtechcon 2009

output value of a function depends only on the input

Montag, 16. November 2009

Page 9: Functional Java Script - Webtechcon 2009

What is it?•programming style

functions, closures, arguments, scope

•mathemetics

•stay focused

•practical, pragmatic

• functions create scope!

Montag, 16. November 2009

Page 10: Functional Java Script - Webtechcon 2009

Another Perspective

nums.slice(0,3)

take 3 nums

Montag, 16. November 2009

Page 11: Functional Java Script - Webtechcon 2009

Demosum.html

http://static.uxebu.com/~cain/functional-examples/sum.html

Montag, 16. November 2009

Page 12: Functional Java Script - Webtechcon 2009

Function creates scope

what else can?

Montag, 16. November 2009

Page 13: Functional Java Script - Webtechcon 2009

•(function(){})()

•create scope

•(function(d){...})(dojo)

•reduce side effects

•prototype overriding can screw you!

Montag, 16. November 2009

Page 14: Functional Java Script - Webtechcon 2009

•(function(){})()

•create scope

•(function(d){...})(dojo)

•reduce side effects

•prototype overriding can screw you!

• function returning a function

•apply/call allow to pass context

•closures

Montag, 16. November 2009

Page 15: Functional Java Script - Webtechcon 2009

Democreate-scope.html

http://static.uxebu.com/~cain/functional-examples/create-scope.html

Montag, 16. November 2009

Page 16: Functional Java Script - Webtechcon 2009

Closures

Montag, 16. November 2009

Page 17: Functional Java Script - Webtechcon 2009

Montag, 16. November 2009

Page 18: Functional Java Script - Webtechcon 2009

Are you lazy!

Montag, 16. November 2009

Page 19: Functional Java Script - Webtechcon 2009

You like to be?

Montag, 16. November 2009

Page 20: Functional Java Script - Webtechcon 2009

Be lazy!

Montag, 16. November 2009

Page 21: Functional Java Script - Webtechcon 2009

Lazy JavaScript...

Montag, 16. November 2009

Page 22: Functional Java Script - Webtechcon 2009

ROXMontag, 16. November 2009

Page 23: Functional Java Script - Webtechcon 2009

Demolazy.html

http://static.uxebu.com/~cain/functional-examples/lazy.html

Montag, 16. November 2009

Page 24: Functional Java Script - Webtechcon 2009

Demohitch.html

http://static.uxebu.com/~cain/functional-examples/hitch.html

Montag, 16. November 2009

Page 25: Functional Java Script - Webtechcon 2009

Use side effects

Montag, 16. November 2009

Page 26: Functional Java Script - Webtechcon 2009

Use side effects

Montag, 16. November 2009

Page 27: Functional Java Script - Webtechcon 2009

Montag, 16. November 2009

Page 28: Functional Java Script - Webtechcon 2009

["00300_car",

"00060_bike",

"00200_motorbike",

...]

[300, 60, 200, ...].sort()

Montag, 16. November 2009

Page 29: Functional Java Script - Webtechcon 2009

Montag, 16. November 2009

Page 30: Functional Java Script - Webtechcon 2009

Montag, 16. November 2009

Page 31: Functional Java Script - Webtechcon 2009

Demodojox.lang.functional.lambda

Montag, 16. November 2009

Page 32: Functional Java Script - Webtechcon 2009

Used where?

•AJAX

• jQuery, dojo, YUI, etc.

•$.each, $.map, ...

•$("div").css("color", "red")

•dojo.hitch()

•etc.

Montag, 16. November 2009

Page 33: Functional Java Script - Webtechcon 2009

Pros + Cons

•reduces cost

•simplify problems

•seperate concerns

•confidence++

• testability

• it's optional

•speed?

• think different

• learn when to use it

Montag, 16. November 2009

Page 34: Functional Java Script - Webtechcon 2009

@wolframkriesing @uxebu

thx, Q&A

Montag, 16. November 2009