Object toSource()
syntax: |
object.toSource() |
return: |
string - a string representation of this object, which can be evaluated or interpreted.
|
description: |
An object may be represented by a string comprised of JavaScript statements which, when evaluated or interpreted, reproduce the object. 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 Object toSource() method and the global.ToSource() function. 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: |
Global.ToSource(), global.eval(), SElib.interpret()
|
example: |
// An Array var a = [1, '2', 3];
Screen.writeln(a.toSource()); Screen.writeln(); Screen.writeln(ToSource(a)); 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(o.toSource()); Screen.writeln(); Screen.writeln(ToSource(o)); 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;"))()) ********************************/ |