2010/Professional JavaScript

From Open Source Bridge Wiki
Jump to: navigation, search

JavaScript is a unique and powerful language. Its ubiquity in the browser and its elegant concurrency model make JavaScript an ideal tool in a number of situations. Learn about the best ways to use and to understand this language from a full-time JavaScript professional.

Speaker: Jesse Hallett

Return to this session's details

Contributed notes

slides: http://sitr.us/talks/professional-javascript/ JiverScripts: http://github.com/jivesoftware/jiverscripts (collection of JavaScript utilities from Jive Software)

functional javascript


Functional Javascript[2]

lexical scope -

javascript in browser won't catch you assigning undefined variables & such. use JSLint[3] to review code. {also good — Douglas Crockford's Javascript Ref. page[4] }

for using '$.getJSON' in-line with 'for' loops, wise not to do 'for' loops, instead use: '[function instance name].forEach.' otherwise, could lose first return.

in javascript, functions are objects that can be called also.

good coding syntax suggestion: variables should be lowercase, new constructors should be capitalized.

properties can be deleted. A function can take a function as a parameter (?)

Many higher order functions aren't implemented in ie.  Can write yourself or import a library

Underscore.js and functional JavaScript are libraries

Lexical scope: determined by where you declare.  If you don't declare it is a global variable.  To catch this use a syntax checker like jslint.  Or some editors have tools to help.  

Ecmascript has a new standard for a strict mode but it's not yet finalized or implemented.

If you declare a variable in a for loop it has same scope as the one declared outside it

Can borrow functions from other objects by using apply

Beware of index variables when using callbacks as the value may increment before the calLback happens.  Eg Ajax is asynchronous.

Pattern of immediately calling function to avoidnpoliting global namespace.  Self calling function

Functions are Objects. Can have attributes and methods.

Object.create easier way to use prototype

Qunit is a test framework that supports asynchronous testing

Mocking frameworks: MockMe: http://johanneslink.net/projects/mockme.html Jack: http://boss.bekk.no/display/BOSS/Jack Mockito: http://jsmockito.org/

TDD Framework for node.js called Exspresso: http://tjholowaychuk.com/post/656851606/expresso-tdd-framework-for-nodejs

"test lifecycles" slide has typo: "same values OR -> ARE not equal"