Q: terminology function, object

Giganews Newsgroups
Subject: Q: terminology function, object
Posted by:  Richard A. DeVenezia (radeve…@ix.netcom.com)
Date: Thu, 4 Sep 2003

First: Many thanks to all the superb help.  This list is a real gem.

I would like to be precise in some messages I alert()

Suppose I have this

function funData () {
  this.balloons = 'yes'
}

function funRender ( funThing ) {
  var fun
  if ( typeof (funThing) == 'function' ) {
    fun = new funThing
  }
  else
  if ( typeof (funThing) == 'object' ) {
    fun = funThing
  }
  else {
    alert ( '1. when you invoke funRender pass it your fun function or fun
object' )
// or
//alert ( '2. when you invoke funRender pass it your fun class or fun
instance' )
    return false
  }

  if (fun.balloons && fun.balloons == 'yes') {
    alert ('You got it, balloons!')
  }

  return true
}

funRender ( funData )
funRender ( new funData )
funRender ( { balloons: 'yes' } )
funRender ( 0 ) // alert
funRender ( 'balloons' ) // alert

alert 1. I think pure JS programmers would grok this best
alert 2. I think someone coming into JS from other languages might grok this
best.

Which has your vote ?

Do I have to unthink this " A function is just an object which has typeof()
= 'function' and can be instantiated" ?

--
Richard A. DeVenezia

Replies