Reputation: 329
I have spidermonkey setup to create objects from custom classes. For instance, in a script i can say...
var d0 = new MyDog();
...and on my app's C++ side a Dog object is created and stored.
What I would like to be able to do is then have that JSObject execute scripts in "it's own space". For example the dog object would execute a script that says...
this.Bark();
...and that dog object would call bark on itself.
With this functionality I could script objects independently.
I haven't found any info on this in the user guide documentation. I thought I could evaluate the script on the individual JSObject rather than the global object, but it doesn't seem to work.
Upvotes: 1
Views: 147
Reputation: 329
Actually, yes. I went back through my code and although I was compile my scripts with the individual object's JSObject, I wasn't evaluating the script with it. Once I made that change I was able to execute scripts in an "individual object spaces".
So to be clear, if you want to execute scripts that operate on a single JSObject, evaluate it with that JSObject and not the global JSObject.
Upvotes: 1