Date v Math as Instance v Static

R

Robert Mark Bram

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
:)
 
D

Douglas Crockford

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.

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.

http://www.crockford.com/#javascript
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top