Subj : Re: How to convert some C-values to jsval? To : =?ISO-8859-1?Q?Georg_Maa=DF?= From : Brendan Eich Date : Mon Aug 04 2003 09:49 pm Georg Maaß wrote: > Brendan Eich wrote: > >> You are reading jsapi.h and the API docs, right? > There is js.c, a tutorial on embedding, and the (buggy, but not useless) API docs on the website. I ask because it seems to me you haven't looked at js.c or the tutorial. > I.e. there are different functions to create an object. like > JS_NewObject, JS_ConstructObject, JS_ConstructObjectWithArguments and > JS_DefineObject. But I never found anything about the differences > between JS_NewObject and JS_ConstructObject. When should I use the one > and when the other? When you need a new object of a class (or of the Object class, in which case you can pass null for the clasp parameter), call JS_NewObject. If the class has a constructor and you want that run on the new object, call JS_ConstructObject. If the constructor requires arguments, call JS_ConstructObjectWithArguments. If you want to call JS_NewObject and (if it succeeds) then JS_DefineProperty the new object so it has a name in another object, call JS_DefineObject. The use of New, Construct, and Define is consistent in the API. New means make a new unconstructed instance, Construct = New + call the class constructor, Define means bind a property name to a value (in the case of DefineObject, a New object). /be .