Date v Math as Instance v Static

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert Mark Bram

    Date v Math as Instance v Static

    Howdy All!

    I am trying to write a very brief comparison of the Date and Math objects in
    terms of instance v static objects. What I have below is my best so far. Any
    criticisms or suggestions are most welcome!

    Date is an instance object.
    You use Date by creating instances of it
    - you call methods on those instances.
    - you change data to do with each instance.
    Instance objects store state
    - meaning they hold data that may change over time.

    Math is a static object.
    You never create instances of it
    - you call methods on Math directly.
    - it never stores data for you: each method performs some mathematical
    computation and returns a result. It is up to you to store required data.
    Static objects can store state - but Math does not.

    Rob
    :)


  • Douglas Crockford

    #2
    Re: Date v Math as Instance v Static

    > I am trying to write a very brief comparison of the Date and Math objects in[color=blue]
    > terms of instance v static objects. What I have below is my best so far. Any
    > criticisms or suggestions are most welcome!
    >
    > Date is an instance object.
    > You use Date by creating instances of it
    > - you call methods on those instances.
    > - you change data to do with each instance.
    > Instance objects store state
    > - meaning they hold data that may change over time.
    >
    > Math is a static object.
    > You never create instances of it
    > - you call methods on Math directly.
    > - it never stores data for you: each method performs some mathematical
    > computation and returns a result. It is up to you to store required data.
    > Static objects can store state - but Math does not.[/color]

    Date is a constructor function. Functions are objects, so it can act as a
    container of [static] functions.

    Math is not a function, it is just an object. It acts as a container for a
    collection of functions.



    Comment

    Working...