Subj : Re: Calling a function within an object To : Zaph From : Brendan Eich Date : Mon Mar 01 2004 02:20 pm Zaph wrote: >Hi, > >I am new to Javascript and Spidermonkey, and encountered a little >problem. > >I have following code in a script: > > var save; > var yyy; > > function add2(x) > { return x+1; > } > > > function add(x) > { y = add2(x); > return y + 1; > } > > You're setting an undeclared global variable, y, here. > function xxx(v1,v2,v3) > { this.v1 = v1; > this.v2 = v2; > this.v3 = v3; > } > > > function test(x) > { save = add(x); > return save; > } > > > add.prototype.add2 = add2; > xxx.prototype.add = add; > > yyy = new xxx("111", "222", "333"); > > >I compile it, evaluate it and then call test from c++ via >"JS_CallFunctionName", and that works fine. As far as i know the >instance of xxx is being generated at the evaluation part of the >script. And therefore the functions "add" and "add2" are created as >well. > > Sure. Why wouldn't it work? >What I need to know now, is how to call "xxx.add" and "xxx.add.add2" > > Those are not references to any properties you've defined. Do you mean xxx.prototype.add and xxx.prototype.add2, or perhaps yyy.add and yyy.add2? >from C++. I need to do this directly and without other functions (i.e. >calling the functions inside the script). > > Try JS_EvaluateScript? /be .