public void ArraySample() { dynamic jsContext = new DynamicJavascriptContext( new JavascriptContext() ); jsContext.a = new object [] { 1, 2, 3 }; // Regular Syntax jsContext.a = jsContext.Array(1, 2, 3); // My Syntax string script = @" a.push(4); "; jsContext.Run(script); Assert.AreEqual(4, jsContext.a.Length); for (var i = 0; i < jsContext.a.Length; i++) { Assert.AreEqual(i + 1, jsContext.a[i]); } }
static void Main(string[] args) { dynamic jsContext = new DynamicJavascriptContext(new JavascriptContext()); jsContext.message = "Hello World !"; jsContext.number = 1; jsContext.array = jsContext.Array(1, 2, 3); jsContext.instance = jsContext.Object(new { b = 2 }); jsContext.instance2 = jsContext.Object(new { a = 1, b = 2 }); string script = @" number = 123; instance['a'] = 1; instance['Date'] = new Date(); instance2['a'] = 123; console.log('Hello log '+instance['Date']); console.log('array.length:'+array.length); array.push(4); for(var i=0; i<array.length; i++) console.log(array[i]); "; jsContext.Run(script); Console.WriteLine("number: " + jsContext.number); Console.WriteLine("instance: " + jsContext.instance); Console.WriteLine("instance.a: " + jsContext.instance.a); Console.WriteLine("instance.b: " + jsContext.instance.b); Console.WriteLine("instance.Date: " + jsContext.instance.Date); Console.WriteLine("instance2.a: " + jsContext.instance2.a); Console.WriteLine("array:" + jsContext.array.Length); Console.WriteLine("array[3]:" + jsContext.array[3]); FunctionCall(); Console.ReadLine(); }