contents   index   previous   next



global.ToSource()

syntax:

ToSource(value)

where:

value - a variable or value to convert to a source string that will reproduce value when the string is evaluated or interpreted.

 

return:

string - a string representation of value, which can be evaluated or interpreted.

 

description:

A variable or value may be represented by a string comprised of JavaScript statements which, when evaluated or interpreted, reproduce the variable or value. The source string may be evaluated by global.eval() or by SElib.interpret(). It is sometimes convenient or powerful to use source strings, for example, in the Data object the DSP object.

 

Though the source string may be read by humans, it is daunting. Remember, ToSource() is designed for interpretation by the ScriptEase interpreters, not by users.

 

The example below compares source strings created by the global.ToSource() function and the Object toSource() method. In these examples, the source strings are identical, which is not guaranteed always to be so. But, no matter which one is used, the source strings can be evaluated or interpreted.

 

see:

Object toSource(), global.eval(), SElib.interpret()

 

example:

// An Array

var a = [1, '2', 3];

 

Screen.writeln(ToSource(a));

Screen.writeln();

Screen.writeln(a.toSource());

Screen.writeln();

/********************************

Displays:

 

((new Function("var tmp1 = [1,\"2\",3]; tmp1[\"0\"] = 1;

tmp1[\"1\"] = \"2\"; tmp1[\"2\"] = 3; return tmp1;"))())

 

((new Function("var tmp1 = [1,\"2\",3]; tmp1[\"0\"] = 1;

tmp1[\"1\"] = \"2\"; tmp1[\"2\"] = 3; return tmp1;"))())

********************************/

 

// An Object

var o = {one:1, two:'2', three:3};

 

Screen.writeln(ToSource(o));

Screen.writeln();

Screen.writeln(o.toSource());

Screen.writeln();

/********************************

Displays:

 

((new Function("var tmp1 = new Object(); tmp1[\"three\"] = 3;

tmp1[\"one\"] = 1; tmp1[\"two\"] = \"2\"; return tmp1;"))())

 

((new Function("var tmp1 = new Object(); tmp1[\"three\"] = 3;

tmp1[\"one\"] = 1; tmp1[\"two\"] = \"2\"; return tmp1;"))())

********************************/

 


global.ToString()