Subj : Re: Rhino: how to use the 'this' keyword in JS To : mesuti@aciworldwide.com From : Igor Bukanov Date : Mon Mar 15 2004 03:33 pm mesuti@aciworldwide.com wrote: > I want to use 'this' keyword in JS. > > I defined a property called 'MyID' and I want to use it inside the JS with > and without "this" keyword. can anybody tell me how to do that? > > > > code snippet: > > > Context cx = Context.enter(); > Scriptable scope = cx.initStandardObjects(null); > > Scriptable id = cx.toObject(new String("012345"), scope); > scope.put("MyID", scope, id); > ... > ... > > > JS: > var myid = MyID; //this must be possible > var myid2 = this.MyID; //this must also be possible > That should work since for scripts 'this' defaults to the scope. Also note that if you want to store a string in MyID, you can simply call: scope.put("MyID", scope, "012345"); Regards, Igor .