Extending javascript

Is there a good reference on the javascript implementation in Servoy?

I know we can use/define global values (w/o var), but the method editor doesn’t allow the “function” keyword.

Can we extend javascript objects with prototypes?

Can we define/use anonymous functions?

If so, how/where?

If not, why?

greg.

Both answers are no.

Servoy uses the (if I am correct forelast) implementation of Rhino but with some tweaks here and there.

It is therefore highly recommended to read/buy the documentation that comes with Servoy.

Seems to me that this is the place to start :)

I did look in the docs, and didn’t find the info I was looking for…and, the Rhino engine does support these advanced javascript options.

In fact, it appears that Servoy does, as well – just the editor doesn’t, which is understandable since Servoy handles the actual function declarations.

If you put your code in a text file, read it in and eval it, it’ll work. Try this:

var s = plugins.file.readTXTFile();
application.output(s);
eval(s);
application.output( boo() );
var str = "test";
application.output( str.boo() );

And you get the output:

boo = function() {return 'boo';}
String.prototype.boo = boo;
boo
boo

(the content of the js file is included in the output)

Now, that said, doing this could be a security/deployment issue. And I don’t know enough about the mechanics of the Javascript implementation in Servoy to know if doing this at startup would make these methods globally available, etc…but I’m very interested in pursing more information on the options here.

greg.

agiletortoise:
I did look in the docs, and didn’t find the info I was looking for…and, the Rhino engine does support these advanced javascript options.

In fact, it appears that Servoy does, as well – just the editor doesn’t, which is understandable since Servoy handles the actual function declarations.

No frickin’ way…it works. :idea: :idea: :idea:

I think you’re in trouble now… :P

agiletortoise:
Can we extend javascript objects with prototypes?

Yes you can, if something is not allowed it will let you know, we locked/sealed several object which are not open for prototyping like the “forms” object.

agiletortoise:
Can we define/use anonymous functions?

Yes you could, if Rhino did not have a issue with anonymous functions, we prevent you from using the function keyword for this reason. Servoy 4.0 will have the latest Rhino, I suppose the issue is resolved in there.