Forging JS – Objects – Javascript



Forging JS – Objects – Javascript

0 0


minhorb-forging.js

Talk given @Minho.rb during the meetup for Semana da Lei 2014.

On Github pfac / minhorb-forging.js

Forging JS

Javascript development tips, tricks and best-practices

by Pedro Costa@iampfac @pfac @pfac

Spoiler alert!

  • Intro for newbies
  • Patterns
  • Prototypes
  • Best-practices

Objects

State

Variables

Behaviour

Functions

Encapsulation

Namespaces

Javascript

Dynamic language

Prototypal

The Prototype Chain

Patterns

Immediately-Invoked Function Expression

Constructor Pattern

Module Pattern

Singleton Pattern

Best practices???

UnderscorevscamelCase

Pure JavascriptvsjQuery/Prototype/whatever

JSLint vs Closure Compiler

Advices

Disclaimer: from my experience

Encapsulate everything

Seriously, EVERYTHING

Singleton or Namespaced Constructor

Tests, tests, tests

Jasmine, QUnit, Mocha...whatever floats your boat

Always var

Literal notations

{} and []new Object and new Array

Follow the standards

Fuck IE...

Progressive Enhancement

Or Graceful Degradationjust do something about it

Decide as a team, and stay on course

  • naming convention
  • spaces vs tabs
  • indentation length

Conclusions

  • Everything is an object
  • Scope, scope, scope...
  • New approaches: First, do no harm
  • Be a team player
  • Test everything

Thank you!

Questions?

References

Douglas Crockford http://javascript.crockford.com/prototypal.html Addy Osmani Learning JavaScript Design Patterns