Subj : Re: Need a few hints on JS_CompileFunction To : Sterling Bates From : Brendan Eich Date : Tue May 18 2004 04:39 pm Sterling Bates wrote: > Brann Joly wrote: > >> I have a few questions about JS_CompileFunction. I did browse >> http://lxr.mozilla.org/mozilla/ident?i=JS_CompileFunction but didnt found >> any sample use. >> >> I don't understand what the obj parameter is for. The Apidoc says it's >> the >> "object with wich the function is associated", but why would I want to do > > > |obj| is the parent, or scope, of the function you are creating. Right. Also, if obj and name are both non-null, the function object created by the compiler will be named as a property of obj. > I can't tell what happens if left null, but I would assume that the parent > is defaulted to global. No, in that case, the parent will be null. As apparently requested by the API caller. The docs need to be fixed to say that obj and name may be null (both, one or the other, or neither -- they're independent). Non-null obj with null name means the function is anonymous, but scoped by obj. Non-null obj with non-null name is a function-valued property of obj, where the function object is scoped by obj. Null obj with non-null name is a named function object with no scope parent. Null obj and name make an anonymous function with no scope parent. /be .