Skip to content

Latest commit

 

History

History
104 lines (67 loc) · 1.75 KB

04_objects.md

File metadata and controls

104 lines (67 loc) · 1.75 KB

!SLIDE center

Objects

!SLIDE bullets incremental

Modules (Mixins in Batman jargon)

  • Observable (gives get, set, observe)
  • EventEmitter (gives fire, prevent, allow)
  • Enumerable (gives filter, reduce given forEach)

!SLIDE bullets incremental

Pretty much everything in the Batman world descends from Batman.Object

class Batman.Object
  $mixin @::, Batman.Observable
  $mixin @::, Batman.EventEmitter
  • The @:: means "this class' prototype"

!SLIDE bullets incremental

Core Classes

  • Batman.Object
  • Batman.Set
  • Batman.SetSort and Batman.SetIndex
  • Batman.Hash
  • Batman.Request
  • Batman.StateMachine

!SLIDE bullets incremental

Subclassing

!SLIDE


class CoolObject extends Batman.Object

!SLIDE


class CoolObject extends Batman.Object
  @accessor 'awesomeness', -> 10

!SLIDE


class CoolObject extends Batman.Object
  @accessor 'awesomeness', -> 10

  @observeAll 'awesomeness', (newAwesomeness) ->

!SLIDE


class CoolObject extends Batman.Object

CoolObject.accessor 'awesomeness', -> 10

CoolObject.observeAll 'awesomeness', (x) ->

!SLIDE


class CoolObject extends Batman.Object
  @observe 'awesomeness', ->

!SLIDE


CoolObject.observe 'awesomeness', (x) ->

!SLIDE

Gotcha

!SLIDE

Classes are people objects too.

!SLIDE


class SomeClass extends Batman.Object

SomeClass.observe 'awesomeness', (x) ->
  console.log x

SomeClass.set 'awesomeness', 10
# => "10" logged to the console