From:  "Dave Huseby" <dave@linuxprogrammer.org>
Date:  19 Oct 2006 05:03:08 Hong Kong Time
Newsgroup:  news.mozilla.org/netscape.public.mozilla.jseng
Subject:  

How do I define an object with a function property setable in JS?

NNTP-Posting-Host:  130.76.32.144

Here what I want to do, assume MyFoo is a custom class defined in my C
code using JS_InitClass, JS_DefineProperties, and JS_DefineFunctions:


var foo = new MyFoo();
foo.onSomeEvent = function()
{
    /* do something useful to handle the onSomeEvent event */
}


I am having trouble defining the onSomeEvent class member such that it
can be assigned a JSFunctionObject.  Is it a property or a function?
If it is a property, do I define it as a JSObject property?

Assuming that onSomeEvent is a property of my class, when I want to
call the function that has been assigned to it, do I just use the
JS_CallFunction function?

I've seen one web page that had details on using resolve hooks to
handle lazy evaluation at runtime.  Is that generally a better/easier
approach than defining all of your properties/functions up front?