Subj : Re: about defining object... To : Youngsun Jeong From : Brendan Eich Date : Wed Oct 01 2003 11:54 pm Youngsun Jeong wrote: >I modified that : > } > else > { > if(!JS_IsConstructing(cx)) > { > if(!js_ValueToObject(cx, argv[0], &obj)) > return JS_FALSE; > } > } > > > So you left the if(argc == 0) obj = NULL; part at the beginning of the constructor? Why? > obj = js_NewObject(cx, &my_class, NULL, NULL); > > if (!obj) > return JS_FALSE; > JS_SetPrivate(cx, obj, argv[0]); Is that right? > > It depends on the type of argv[0]. What type do you want the age slot to have? >And I tested my code. See below ; > testscript : > function sumage(age) > { > var myage = age.plusAge(10); //myage = age + 10 > return myage; > } > "age" value is integer. >But, it's not working. I got the error message "TypeError: age.plusAge >is not a function". > >What is wrong? How "age" value is passed to function "plusAge()" >*without* constructing myobject(that is "var myobj = new myobject();") >*on the script*? > > How are you calling sumage? Please show complete examples. If you didn't pass a new myobject instance as the age parameter to sumage, then of course you'll get an error. /be .