Functions passed as arguments

Giganews Newsgroups
Subject: Functions passed as arguments
Posted by:  Richard A. DeVenezia (radeve…@ix.netcom.com)
Date: Mon, 1 Sep 2003

I have a function source() to show the definitions of functions passed to it

function sourceAsHTML() {
  var s=''
  for (var i=0; i<arguments.length; i++) {
  alert(arguments[i])
    s +=
    '<PRE>'
  + arguments[i].toString().replace (/</g, '&lt;')
  + '</PRE>'
  }
  return s
}

and it works nicely, except in the case of a class prototype assigned to an
anonymous function
i.e.

function myClass () {}
function myClass.prototype.foobar = function () { /* foobar */ }

alert (sourceAsHTML(myClass.prototype.foobar))

.....
the alert shows
<PRE>function () { /* foobar */ }</PRE>
which is close, but it doesn't show that it 'belongs' to
myClass.prototype.foobar.

So the question is, when passed a function as an arg is there a way to know
the function name or context (i.e. prototype) ?

--
Richard A. DeVenezia

Replies