On 2008.12.10., at 16:35, Johan Compagner wrote:

also all our code are standalone functions like

function test()
{
  // code
}

if i compile that as a script and say exec() then nothing happens because it doesnt exec the function but just the scripts (which doesnt do anything)

It does. It creates a function object and binds it to the property name "test" within the scope.


besides that suddenly having arguments also is not possible for us because many of our customers use "arguments" we cant just change that. So using a
Script instead of a Function is just not possible

I am currently investigating why it is that function object cant just be as a script, why we really need to have suddenly a parent and prototype scope which a Script (which also can have the same function it it) doesnt seem to
need

Here's a distinction:

As the JS spec does not define a runtime representation for the program, a script is not a first-class JS object. It is Rhino's implementation-specific representation of a JS program. There's no way to access or manipulate it within the program itself.

A function, on the other hand, is a first-class object in JavaScript. I.e. it is a Scriptable, and it also has a prototype (the standard Function object, which is why you need to have a scope with standard objects in it to create a function). As such, function objects are bound to a scope, scripts are not. Function objects are really created when a program executes a function statement or a function expression; and as any other first-class JS object, function objects are mutable (sort of - you can add/remove arbitrary properties to them, but you can't modify their code).

johan

Attila.

--
home: http://www.szegedi.org
twitter: http://twitter.com/szegedi
weblog: http://constc.blogspot.com
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to