<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="/rss.xsl"?><rss version="2.0"><channel><title>jurassic Wiki Rss Feed</title><link>http://jurassic.codeplex.com/</link><description>jurassic Wiki Rss Description</description><item><title>Updated Wiki: Home</title><link>https://jurassic.codeplex.com/wikipage?version=48</link><description>&lt;div class="wikidoc"&gt;&lt;h3&gt;What is Jurassic?&lt;/h3&gt;
&lt;br /&gt;Jurassic is an implementation of the ECMAScript language and runtime.  It aims to provide the best performing and most standards-compliant implementation of JavaScript for .NET.  Jurassic is not intended for end-users; instead it is intended to be integrated into .NET programs.  If you are the author of a .NET program, you can use Jurassic to compile and execute JavaScript code.&lt;br /&gt;
&lt;h3&gt;Features&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Supports all ECMAScript 3 and ECMAScript 5 functionality, including ES5 strict mode&lt;/li&gt;
&lt;li&gt;Well tested - passes over five thousand unit tests (with over thirty thousand asserts)&lt;/li&gt;
&lt;li&gt;Simple yet powerful API&lt;/li&gt;
&lt;li&gt;Compiles JavaScript into .NET bytecode (CIL); not an interpreter&lt;/li&gt;
&lt;li&gt;Deployed as a single .NET assembly (no native code)&lt;/li&gt;
&lt;li&gt;Basic support for integrated debugging within Visual Studio&lt;/li&gt;
&lt;li&gt;Uses light-weight code generation, so generated code is fully garbage collected&lt;/li&gt;
&lt;li&gt;Tested on .NET 3.5, .NET 4 and Silverlight&lt;/li&gt;&lt;/ul&gt;

&lt;h3&gt;See Also&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="https://jurassic.codeplex.com/documentation?referringTitle=Home"&gt;Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jurassic.codeplex.com/wikipage?title=Conformance&amp;referringTitle=Home"&gt;Conformance&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jurassic.codeplex.com/wikipage?title=Benchmarks&amp;referringTitle=Home"&gt;Benchmarks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jurassic.codeplex.com/wikipage?title=Future%20plans&amp;referringTitle=Home"&gt;Future plans&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h3&gt;Try it Now&lt;/h3&gt;
You can enter javascript commands into the console below (requires silverlight).&lt;br /&gt;&lt;object data="data:application/x-silverlight-2," type="application/x-silverlight-2" style="height:220px;width:600px;"&gt;&lt;param name="source" value="https://jurassicservices.appspot.com/silverlight/SilverlightREPL.xap"&gt;&lt;/param&gt;&lt;param name="windowless" value="true"&gt;&lt;/param&gt;&lt;param name="minRuntimeVersion" value="5.0.61118.0"&gt;&lt;/param&gt;&lt;param name="autoUpgrade" value="true"&gt;&lt;/param&gt;&lt;p&gt;You need to install Microsoft Silverlight to view this content. &lt;a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=5.0.61118.0" style="text-decoration:none;"&gt;Get Silverlight!&lt;br /&gt;&lt;img src="http://go.microsoft.com/fwlink/?LinkID=108181" alt="Get Microsoft Silverlight" style="border-style:none;" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;/object&gt;&lt;iframe style="visibility:hidden;height:0;width:0;border-width:0;"&gt;&lt;/iframe&gt;&lt;br /&gt;Example: 5+5&lt;br /&gt;Example: Math.sin(3)&lt;br /&gt;Example: for(var i=0;i&amp;lt;8;i++)console.log(i&amp;amp;2?new Array((i&amp;amp;1)+1).join(&amp;#39; &amp;#39;)+&amp;#39;\\&amp;#39;:new Array(2-(i&amp;amp;1)).join(&amp;#39; &amp;#39;)+&amp;#39;/&amp;#39;)&lt;br /&gt;
&lt;h3&gt;Acknowledgements&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Thanks to &lt;a href="http://www.jetbrains.com/"&gt;JetBrains&lt;/a&gt; for providing a free license for &lt;a href="http://www.jetbrains.com/profiler/"&gt;dotTrace Performance 4.0&lt;/a&gt;!&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>paulbartrum</author><pubDate>Tue, 30 Apr 2013 00:09:40 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20130430120940A</guid></item><item><title>Updated Wiki: Home</title><link>https://jurassic.codeplex.com/wikipage?version=47</link><description>&lt;div class="wikidoc"&gt;&lt;h3&gt;What is Jurassic?&lt;/h3&gt;
&lt;br /&gt;Jurassic is an implementation of the ECMAScript language and runtime.  It aims to provide the best performing and most standards-compliant implementation of JavaScript for .NET.  Jurassic is not intended for end-users; instead it is intended to be integrated into .NET programs.  If you are the author of a .NET program, you can use Jurassic to compile and execute JavaScript code.&lt;br /&gt;
&lt;h3&gt;Features&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Supports all ECMAScript 3 and ECMAScript 5 functionality, including ES5 strict mode&lt;/li&gt;
&lt;li&gt;Well tested - passes over five thousand unit tests (with over thirty thousand asserts)&lt;/li&gt;
&lt;li&gt;Simple yet powerful API&lt;/li&gt;
&lt;li&gt;Compiles JavaScript into .NET bytecode (CIL); not an interpreter&lt;/li&gt;
&lt;li&gt;Deployed as a single .NET assembly (no native code)&lt;/li&gt;
&lt;li&gt;Basic support for integrated debugging within Visual Studio&lt;/li&gt;
&lt;li&gt;Uses light-weight code generation, so generated code is fully garbage collected&lt;/li&gt;
&lt;li&gt;Tested on .NET 3.5, .NET 4 and Silverlight&lt;/li&gt;&lt;/ul&gt;

&lt;h3&gt;See Also&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="https://jurassic.codeplex.com/documentation?referringTitle=Home"&gt;Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jurassic.codeplex.com/wikipage?title=Conformance&amp;referringTitle=Home"&gt;Conformance&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jurassic.codeplex.com/wikipage?title=Benchmarks&amp;referringTitle=Home"&gt;Benchmarks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jurassic.codeplex.com/wikipage?title=Future%20plans&amp;referringTitle=Home"&gt;Future plans&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h3&gt;Try it Now&lt;/h3&gt;
You can enter javascript commands into the console below (requires silverlight).&lt;br /&gt;&lt;object data="data:application/x-silverlight-2," type="application/x-silverlight-2" style="height:220px;width:600px;"&gt;&lt;param name="source" value="file://jurassicservices.appspot.com/silverlight/SilverlightREPL.xap"&gt;&lt;/param&gt;&lt;param name="windowless" value="true"&gt;&lt;/param&gt;&lt;param name="minRuntimeVersion" value="5.0.61118.0"&gt;&lt;/param&gt;&lt;param name="autoUpgrade" value="true"&gt;&lt;/param&gt;&lt;p&gt;You need to install Microsoft Silverlight to view this content. &lt;a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=5.0.61118.0" style="text-decoration:none;"&gt;Get Silverlight!&lt;br /&gt;&lt;img src="http://go.microsoft.com/fwlink/?LinkID=108181" alt="Get Microsoft Silverlight" style="border-style:none;" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;/object&gt;&lt;iframe style="visibility:hidden;height:0;width:0;border-width:0;"&gt;&lt;/iframe&gt;&lt;br /&gt;Example: 5+5&lt;br /&gt;Example: Math.sin(3)&lt;br /&gt;Example: for(var i=0;i&amp;lt;8;i++)console.log(i&amp;amp;2?new Array((i&amp;amp;1)+1).join(&amp;#39; &amp;#39;)+&amp;#39;\\&amp;#39;:new Array(2-(i&amp;amp;1)).join(&amp;#39; &amp;#39;)+&amp;#39;/&amp;#39;)&lt;br /&gt;
&lt;h3&gt;Acknowledgements&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Thanks to &lt;a href="http://www.jetbrains.com/"&gt;JetBrains&lt;/a&gt; for providing a free license for &lt;a href="http://www.jetbrains.com/profiler/"&gt;dotTrace Performance 4.0&lt;/a&gt;!&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>paulbartrum</author><pubDate>Tue, 30 Apr 2013 00:09:03 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20130430120903A</guid></item><item><title>New Comment on "Benchmarks"</title><link>http://jurassic.codeplex.com/wikipage?title=Benchmarks&amp;ANCHOR#C27081</link><description>Numbers are milliseconds, and lower is better.</description><author>paulbartrum</author><pubDate>Thu, 04 Apr 2013 10:24:08 GMT</pubDate><guid isPermaLink="false">New Comment on "Benchmarks" 20130404102408A</guid></item><item><title>New Comment on "Benchmarks"</title><link>http://jurassic.codeplex.com/wikipage?title=Benchmarks&amp;ANCHOR#C27066</link><description>What unit are these numbers in&amp;#63;  Is lower better or higher&amp;#63;&amp;#63;</description><author>stonstad</author><pubDate>Wed, 03 Apr 2013 16:57:21 GMT</pubDate><guid isPermaLink="false">New Comment on "Benchmarks" 20130403045721P</guid></item><item><title>New Comment on "Debugging"</title><link>http://jurassic.codeplex.com/wikipage?title=Debugging&amp;ANCHOR#C24868</link><description>Global variables are not locals, so I don&amp;#39;t think you can call DeclareLocal on them &amp;#58;-&amp;#41;  To get the value of a global variable, call scope.GetValue&amp;#40;&amp;#34;name of global&amp;#34;&amp;#41; &amp;#40;where &amp;#34;scope&amp;#34; is the second parameter of the generated method&amp;#41;.</description><author>paulbartrum</author><pubDate>Sun, 02 Sep 2012 23:42:03 GMT</pubDate><guid isPermaLink="false">New Comment on "Debugging" 20120902114203P</guid></item><item><title>New Comment on "Debugging"</title><link>http://jurassic.codeplex.com/wikipage?title=Debugging&amp;ANCHOR#C24858</link><description>One extra comment, the locals will only work for variables that are inside a function, so I debug it like this&amp;#58;&amp;#10;&amp;#10;function test&amp;#40;&amp;#41; &amp;#123;&amp;#10;debugger&amp;#59;&amp;#47;&amp;#47;&amp;#10;var x&amp;#59; &amp;#47;&amp;#47; Shows is locals window&amp;#10;&amp;#125;&amp;#10;test&amp;#40;&amp;#41;&amp;#59;&amp;#10;&amp;#10;Looks like global variables don&amp;#39;t call the the DeclareLocal method on ILGenerator</description><author>XIU</author><pubDate>Fri, 31 Aug 2012 15:31:09 GMT</pubDate><guid isPermaLink="false">New Comment on "Debugging" 20120831033109P</guid></item><item><title>New Comment on "Debugging"</title><link>http://jurassic.codeplex.com/wikipage?title=Debugging&amp;ANCHOR#C24857</link><description>I&amp;#39;ve got the locals window working&amp;#58;&amp;#10;&amp;#10;in MethodGenerator.cs&amp;#58;&amp;#10;-                    optimizationInfo.DebugDocument &amp;#61; reflectionEmitInfo.ModuleBuilder.DefineDocument&amp;#40;this.Source.Path, COMHelpers.LanguageType, COMHelpers.LanguageVendor, COMHelpers.DocumentType&amp;#41;&amp;#59;&amp;#10;-                    methodBuilder.DefineParameter&amp;#40;1, System.Reflection.ParameterAttributes.None, &amp;#34;scriptEngine&amp;#34;&amp;#41;&amp;#59;&amp;#10;-                    methodBuilder.DefineParameter&amp;#40;2, System.Reflection.ParameterAttributes.None, &amp;#34;scope&amp;#34;&amp;#41;&amp;#59;&amp;#10;-                    methodBuilder.DefineParameter&amp;#40;3, System.Reflection.ParameterAttributes.None, &amp;#34;thisValue&amp;#34;&amp;#41;&amp;#59;&amp;#10;-                    generator.MarkSequencePoint&amp;#40;optimizationInfo.DebugDocument, new SourceCodeSpan&amp;#40;1, 1, 1, 1&amp;#41;&amp;#41;&amp;#59;&amp;#10;&amp;#43;                    optimizationInfo.DebugDocument &amp;#61; reflectionEmitInfo.ModuleBuilder.DefineDocument&amp;#40;this.Source.Path, Guid.Empty, Guid.Empty, Guid.Empty&amp;#41;&amp;#59;&amp;#47;&amp;#47;, COMHelpers.LanguageType, COMHelpers.LanguageVendor, COMHelpers.DocumentType&amp;#41;&amp;#59;&amp;#10;&amp;#43;                    &amp;#47;&amp;#47;methodBuilder.DefineParameter&amp;#40;1, System.Reflection.ParameterAttributes.None, &amp;#34;scriptEngine&amp;#34;&amp;#41;&amp;#59;&amp;#10;&amp;#43;                    &amp;#47;&amp;#47;methodBuilder.DefineParameter&amp;#40;2, System.Reflection.ParameterAttributes.None, &amp;#34;scope&amp;#34;&amp;#41;&amp;#59;&amp;#10;&amp;#43;                    &amp;#47;&amp;#47;methodBuilder.DefineParameter&amp;#40;3, System.Reflection.ParameterAttributes.None, &amp;#34;thisValue&amp;#34;&amp;#41;&amp;#59;&amp;#10;&amp;#43;                    &amp;#47;&amp;#47;generator.MarkSequencePoint&amp;#40;optimizationInfo.DebugDocument, new SourceCodeSpan&amp;#40;1, 1, 1, 1&amp;#41;&amp;#41;&amp;#59;&amp;#10;&amp;#10;in ReflactionEmitILGenerator.cs&amp;#58;&amp;#10;-            return new ReflectionEmitILLocalVariable&amp;#40;this.generator.DeclareLocal&amp;#40;type&amp;#41;, name&amp;#41;&amp;#59;&amp;#10;&amp;#43;            var declareLocal &amp;#61; this.generator.DeclareLocal&amp;#40;type&amp;#41;&amp;#59;&amp;#10;&amp;#43;            if &amp;#40;name &amp;#33;&amp;#61; null &amp;#38;&amp;#38; name &amp;#33;&amp;#61; &amp;#34;returnValue&amp;#34;&amp;#41;&amp;#10;&amp;#43;                declareLocal.SetLocalSymInfo&amp;#40;name&amp;#41;&amp;#59;&amp;#10;&amp;#43;            return new ReflectionEmitILLocalVariable&amp;#40;declareLocal, name&amp;#41;&amp;#59;&amp;#10;&amp;#10;in OptimizationInfo.cs&amp;#58;&amp;#10;                 return this.MethodOptimizationHints.HasArguments &amp;#61;&amp;#61; false &amp;#38;&amp;#38;&amp;#10;                     this.MethodOptimizationHints.HasEval &amp;#61;&amp;#61; false &amp;#38;&amp;#38;&amp;#10;                     this.MethodOptimizationHints.HasNestedFunction &amp;#61;&amp;#61; false &amp;#38;&amp;#38;&amp;#10;-                    this.EvalResult &amp;#61;&amp;#61; null&amp;#59;&amp;#10;&amp;#43;                    this.EvalResult &amp;#61;&amp;#61; null &amp;#38;&amp;#38;&amp;#10;&amp;#43;                    this.DebugDocument &amp;#61;&amp;#61; null&amp;#59;</description><author>XIU</author><pubDate>Fri, 31 Aug 2012 12:40:45 GMT</pubDate><guid isPermaLink="false">New Comment on "Debugging" 20120831124045P</guid></item><item><title>Updated Wiki: Exposing a .NET class to JavaScript</title><link>http://jurassic.codeplex.com/wikipage?title=Exposing a .NET class to JavaScript&amp;version=9</link><description>&lt;div class="wikidoc"&gt;&lt;h2&gt;Exposing a .NET class to JavaScript&lt;/h2&gt;
&lt;h3&gt;Building a property bag class&lt;/h3&gt;
To start with, let&amp;#39;s create a class that contains a couple of properties.&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic.Library;

&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; AppInfo : ObjectInstance
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; AppInfo(ScriptEngine engine)
        : &lt;span style="color:Blue;"&gt;base&lt;/span&gt;(engine)
    {
        &lt;span style="color:Green;"&gt;// Read-write property (name).&lt;/span&gt;
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;[&lt;span style="color:#A31515;"&gt;&amp;quot;name&amp;quot;&lt;/span&gt;] = &lt;span style="color:#A31515;"&gt;&amp;quot;Test Application&amp;quot;&lt;/span&gt;;

        &lt;span style="color:Green;"&gt;// Read-only property (version).&lt;/span&gt;
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.DefineProperty(&lt;span style="color:#A31515;"&gt;&amp;quot;version&amp;quot;&lt;/span&gt;, &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PropertyDescriptor(5, PropertyAttributes.Sealed), &lt;span style="color:Blue;"&gt;true&lt;/span&gt;);
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;In this example there are a few things to note:
&lt;ul&gt;&lt;li&gt;Classes that are exposed to JavaScript are required to inherit from &lt;b&gt;Jurassic.Library.ObjectInstance&lt;/b&gt;.&lt;/li&gt;
&lt;li&gt;Passing a ScriptEngine to the base class constructor means that the object will have no prototype.  Therefore the usual functions (hasOwnProperty, toString) will not be available.&lt;/li&gt;
&lt;li&gt;The class indexer can be used to create read-write properties.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;DefineProperty&lt;/b&gt; can be used to create read-only properties.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;Here&amp;#39;s an example of how to create and use the new class:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; engine = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Jurassic.ScriptEngine();
engine.SetGlobalValue(&lt;span style="color:#A31515;"&gt;&amp;quot;appInfo&amp;quot;&lt;/span&gt;, &lt;span style="color:Blue;"&gt;new&lt;/span&gt; AppInfo(engine));
Console.WriteLine(engine.Evaluate&amp;lt;&lt;span style="color:Blue;"&gt;string&lt;/span&gt;&amp;gt;(&lt;span style="color:#A31515;"&gt;&amp;quot;appInfo.name + &amp;#39; &amp;#39; + appInfo.version&amp;quot;&lt;/span&gt;));
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This will output &amp;quot;Test Application 5&amp;quot; to the console.&lt;br /&gt;&lt;br /&gt;
&lt;h3&gt;Building a class with static functions&lt;/h3&gt;
The next step up is to create a class with static functions, similar to how the built-in Math object works.  For example, say you want to create a new Math2 object with a log10 function:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic.Library;

&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; Math2 : ObjectInstance
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; Math2(ScriptEngine engine)
        : &lt;span style="color:Blue;"&gt;base&lt;/span&gt;(engine)
    {
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.PopulateFunctions();
    }

    [JSFunction(Name = &lt;span style="color:#A31515;"&gt;&amp;quot;log10&amp;quot;&lt;/span&gt;)]
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;static&lt;/span&gt; &lt;span style="color:Blue;"&gt;double&lt;/span&gt; Log10(&lt;span style="color:Blue;"&gt;double&lt;/span&gt; num)
    {
        &lt;span style="color:Blue;"&gt;return&lt;/span&gt; Math.Log10(num);
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Note the following:
&lt;ul&gt;&lt;li&gt;&lt;b&gt;PopulateFunctions&lt;/b&gt; searches the class for &lt;a href="http://jurassic.codeplex.com/wikipage?title=JSFunction&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;JSFunction&lt;/a&gt; attributes and creates a function for each one it finds.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://jurassic.codeplex.com/wikipage?title=JSFunction&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;JSFunction&lt;/a&gt; attributes allows the JavaScript function name to be different from the .NET method name.&lt;/li&gt;
&lt;li&gt;The parameter types and the return type must be on the list of &lt;a href="http://jurassic.codeplex.com/wikipage?title=Supported%20types&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;supported types&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Please note: This feature requires the latest build from source control and is not yet in the official Downloads&lt;/i&gt; Decorating a property with the &lt;a href="http://jurassic.codeplex.com/wikipage?title=JSProperty&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;JSProperty&lt;/a&gt; attribute allows properties to be exposed to script as accessors.  You can therefore code properties, complete with backers, in CLR, or make read-only properties in CLR code.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;Here&amp;#39;s an example of how to create and use the new class:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; engine = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Jurassic.ScriptEngine();
engine.SetGlobalValue(&lt;span style="color:#A31515;"&gt;&amp;quot;math2&amp;quot;&lt;/span&gt;, &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Math2(engine));
Console.WriteLine(engine.Evaluate&amp;lt;&lt;span style="color:Blue;"&gt;double&lt;/span&gt;&amp;gt;(&lt;span style="color:#A31515;"&gt;&amp;quot;math2.log10(1000)&amp;quot;&lt;/span&gt;));
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This will output &amp;quot;3&amp;quot; to the console.&lt;br /&gt;&lt;br /&gt;
&lt;h3&gt;Building an instance class&lt;/h3&gt;
Objects that can be instantiated, like the built-in Number, String, Array and RegExp objects, require two .NET classes, one for the constructor and one for the instance.  For example, let&amp;#39;s make a JavaScript object that works similar to the .NET Random class (with a seed, since JavaScript doesn&amp;#39;t support this):&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic.Library;

&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; RandomConstructor : ClrFunction
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; RandomConstructor(ScriptEngine engine)
        : &lt;span style="color:Blue;"&gt;base&lt;/span&gt;(engine.Function.InstancePrototype, &lt;span style="color:#A31515;"&gt;&amp;quot;Random&amp;quot;&lt;/span&gt;, &lt;span style="color:Blue;"&gt;new&lt;/span&gt; RandomInstance(engine.Object.InstancePrototype))
    {
    }

    [JSConstructorFunction]
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; RandomInstance Construct(&lt;span style="color:Blue;"&gt;int&lt;/span&gt; seed)
    {
        &lt;span style="color:Blue;"&gt;return&lt;/span&gt; &lt;span style="color:Blue;"&gt;new&lt;/span&gt; RandomInstance(&lt;span style="color:Blue;"&gt;this&lt;/span&gt;.InstancePrototype, seed);
    }
}

&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; RandomInstance : ObjectInstance
{
    &lt;span style="color:Blue;"&gt;private&lt;/span&gt; Random random;

    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; RandomInstance(ObjectInstance prototype)
        : &lt;span style="color:Blue;"&gt;base&lt;/span&gt;(prototype)
    {
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.PopulateFunctions();
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.random = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Random(0);
    }

    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; RandomInstance(ObjectInstance prototype, &lt;span style="color:Blue;"&gt;int&lt;/span&gt; seed)
        : &lt;span style="color:Blue;"&gt;base&lt;/span&gt;(prototype)
    {
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.random = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Random(seed);
    }

    [JSFunction(Name = &lt;span style="color:#A31515;"&gt;&amp;quot;nextDouble&amp;quot;&lt;/span&gt;)]
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;double&lt;/span&gt; NextDouble()
    {
        &lt;span style="color:Blue;"&gt;return&lt;/span&gt; &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.random.NextDouble();
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Note the following:
&lt;ul&gt;&lt;li&gt;You need two classes - one is the constructor (i.e. the function object that you call new on) and one is for the instance object.&lt;/li&gt;
&lt;li&gt;The ClrFunction base class requires three parameters: the prototype for the function object, the name of the function and the prototype for any instances created using the function.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://jurassic.codeplex.com/wikipage?title=JSConstructorFunction&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;JSConstructorFunction&lt;/a&gt; attribute marks the method that is called when the &lt;b&gt;new&lt;/b&gt; operator is used.  You can also use &lt;a href="http://jurassic.codeplex.com/wikipage?title=JSCallFunction&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;JSCallFunction&lt;/a&gt; to mark the method that is called when the function is called directly.&lt;/li&gt;
&lt;li&gt;The RandomInstance class has two constructors - one is used to initialize the prototype, one is used to initialize all other instances.  &lt;b&gt;PopulateFunctions&lt;/b&gt; should only be called from the prototype object.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;Here&amp;#39;s an example of how to create and use the new class:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; engine = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Jurassic.ScriptEngine();
engine.SetGlobalValue(&lt;span style="color:#A31515;"&gt;&amp;quot;Random&amp;quot;&lt;/span&gt;, &lt;span style="color:Blue;"&gt;new&lt;/span&gt; RandomConstructor(engine));
Console.WriteLine(engine.Evaluate&amp;lt;&lt;span style="color:Blue;"&gt;double&lt;/span&gt;&amp;gt;(&lt;span style="color:#A31515;"&gt;&amp;quot;var rand = new Random(1000); rand.nextDouble()&amp;quot;&lt;/span&gt;));
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This will output &amp;quot;0.151557459100875&amp;quot; to the console (since we are using a seed, the first call to nextDouble() will be the same every time).&lt;br /&gt;&lt;br /&gt;This example is much more involved, but it supports all of the advanced JavaScript concepts:
&lt;ul&gt;&lt;li&gt;&lt;i&gt;rand&lt;/i&gt; supports the built-in Object functions (hasOwnProperty, toString, etc).&lt;/li&gt;
&lt;li&gt;&lt;i&gt;rand&lt;/i&gt; utilizes prototypical inheritance.  In this case you have the following prototype chain: random instance (with no properties) -&amp;gt; random prototype (with nextDouble defined) -&amp;gt; object prototype -&amp;gt; null.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;br /&gt;Next tutorial: &lt;a href="http://jurassic.codeplex.com/wikipage?title=Loading%20a%20script%20from%20a%20custom%20source&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;Loading a script from a custom source&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>paulbartrum</author><pubDate>Sat, 07 Apr 2012 07:02:36 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Exposing a .NET class to JavaScript 20120407070236A</guid></item><item><title>Updated Wiki: Exposing a .NET class to JavaScript</title><link>http://jurassic.codeplex.com/wikipage?title=Exposing a .NET class to JavaScript&amp;version=8</link><description>&lt;div class="wikidoc"&gt;&lt;h2&gt;Exposing a .NET class to JavaScript&lt;/h2&gt;
&lt;h3&gt;Building a property bag class&lt;/h3&gt;
To start with, let&amp;#39;s create a class that contains a couple of properties.&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic.Library;

&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; AppInfo : ObjectInstance
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; AppInfo(ScriptEngine engine)
        : &lt;span style="color:Blue;"&gt;base&lt;/span&gt;(engine)
    {
        &lt;span style="color:Green;"&gt;// Read-write property (name).&lt;/span&gt;
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;[&lt;span style="color:#A31515;"&gt;&amp;quot;name&amp;quot;&lt;/span&gt;] = &lt;span style="color:#A31515;"&gt;&amp;quot;Test Application&amp;quot;&lt;/span&gt;;

        &lt;span style="color:Green;"&gt;// Read-only property (version).&lt;/span&gt;
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.DefineProperty(&lt;span style="color:#A31515;"&gt;&amp;quot;version&amp;quot;&lt;/span&gt;, &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PropertyDescriptor(5, PropertyAttributes.Sealed), &lt;span style="color:Blue;"&gt;true&lt;/span&gt;);
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;In this example there are a few things to note:
&lt;ul&gt;&lt;li&gt;Classes that are exposed to JavaScript are required to inherit from &lt;b&gt;Jurassic.Library.ObjectInstance&lt;/b&gt;.&lt;/li&gt;
&lt;li&gt;Passing a ScriptEngine to the base class constructor means that the object will have no prototype.  Therefore the usual functions (hasOwnProperty, toString) will not be available.&lt;/li&gt;
&lt;li&gt;The class indexer can be used to create read-write properties.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;DefineProperty&lt;/b&gt; can be used to create read-only properties.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;Here&amp;#39;s an example of how to create and use the new class:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; engine = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Jurassic.ScriptEngine();
engine.SetGlobalValue(&lt;span style="color:#A31515;"&gt;&amp;quot;appInfo&amp;quot;&lt;/span&gt;, &lt;span style="color:Blue;"&gt;new&lt;/span&gt; AppInfo(engine));
Console.WriteLine(engine.Evaluate&amp;lt;&lt;span style="color:Blue;"&gt;string&lt;/span&gt;&amp;gt;(&lt;span style="color:#A31515;"&gt;&amp;quot;appInfo.name + &amp;#39; &amp;#39; + appInfo.version&amp;quot;&lt;/span&gt;));
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This will output &amp;quot;Test Application 5&amp;quot; to the console.&lt;br /&gt;&lt;br /&gt;
&lt;h3&gt;Building a class with static functions&lt;/h3&gt;
The next step up is to create a class with static functions, similar to how the built-in Math object works.  For example, say you want to create a new Math2 object with a log10 function:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic.Library;

&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; Math2 : ObjectInstance
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; Math2(ScriptEngine engine)
        : &lt;span style="color:Blue;"&gt;base&lt;/span&gt;(engine)
    {
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.PopulateFunctions();
    }

    [JSFunction(Name = &lt;span style="color:#A31515;"&gt;&amp;quot;log10&amp;quot;&lt;/span&gt;)]
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;static&lt;/span&gt; &lt;span style="color:Blue;"&gt;double&lt;/span&gt; Log10(&lt;span style="color:Blue;"&gt;double&lt;/span&gt; num)
    {
        &lt;span style="color:Blue;"&gt;return&lt;/span&gt; Math.Log10(num);
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Note the following:
&lt;ul&gt;&lt;li&gt;&lt;b&gt;PopulateFunctions&lt;/b&gt; searches the class for &lt;a href="http://jurassic.codeplex.com/wikipage?title=JSFunction&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;JSFunction&lt;/a&gt; attributes and creates a function for each one it finds.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://jurassic.codeplex.com/wikipage?title=JSFunction&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;JSFunction&lt;/a&gt; attributes allows the JavaScript function name to be different from the .NET method name.&lt;/li&gt;
&lt;li&gt;The parameter types and the return type must be on the list of &lt;a href="http://jurassic.codeplex.com/wikipage?title=Supported%20types&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;supported types&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Please note: This feature requires the latest build from source control and is not yet in the official Downloads&lt;/i&gt; Decorating a property with the &lt;a href="http://jurassic.codeplex.com/wikipage?title=JSProperty&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;JSProperty&lt;/a&gt; attribute allows properties to be exposed to script as accessors.  You can therefore code properties, complete with backers, in CLR, or make read-only properties in CLR code.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;Here&amp;#39;s an example of how to create and use the new class:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; engine = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Jurassic.ScriptEngine();
engine.SetGlobalValue(&lt;span style="color:#A31515;"&gt;&amp;quot;math2&amp;quot;&lt;/span&gt;, &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Math2(engine));
Console.WriteLine(engine.Evaluate&amp;lt;&lt;span style="color:Blue;"&gt;double&lt;/span&gt;&amp;gt;(&lt;span style="color:#A31515;"&gt;&amp;quot;math2.log10(1000)&amp;quot;&lt;/span&gt;));
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This will output &amp;quot;3&amp;quot; to the console.&lt;br /&gt;&lt;br /&gt;
&lt;h3&gt;Building an instance class&lt;/h3&gt;
Objects that can be instantiated, like the built-in Number, String, Array and RegExp objects, require two .NET classes, one for the constructor and one for the instance.  For example, let&amp;#39;s make a JavaScript object that works similar to the .NET Random class (with a seed, since JavaScript doesn&amp;#39;t support this):&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic.Library;

&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; RandomConstructor : ClrFunction
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; RandomConstructor(ScriptEngine engine)
        : &lt;span style="color:Blue;"&gt;base&lt;/span&gt;(engine.Function.InstancePrototype, &lt;span style="color:#A31515;"&gt;&amp;quot;Random&amp;quot;&lt;/span&gt;, &lt;span style="color:Blue;"&gt;new&lt;/span&gt; RandomInstance(engine.Object.InstancePrototype))
    {
    }

    [JSConstructorFunction]
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; RandomInstance Construct(&lt;span style="color:Blue;"&gt;int&lt;/span&gt; seed)
    {
        &lt;span style="color:Blue;"&gt;return&lt;/span&gt; &lt;span style="color:Blue;"&gt;new&lt;/span&gt; RandomInstance(&lt;span style="color:Blue;"&gt;this&lt;/span&gt;.InstancePrototype, seed);
    }
}

&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; RandomInstance : ObjectInstance
{
    &lt;span style="color:Blue;"&gt;private&lt;/span&gt; Random random;

    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; RandomInstance(ObjectInstance prototype)
        : &lt;span style="color:Blue;"&gt;base&lt;/span&gt;(prototype)
    {
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.PopulateFunctions();
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.random = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Random(0);
    }

    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; RandomInstance(ObjectInstance prototype, &lt;span style="color:Blue;"&gt;int&lt;/span&gt; seed)
        : &lt;span style="color:Blue;"&gt;base&lt;/span&gt;(prototype)
    {
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.random = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Random(seed);
    }

    [JSFunction(Name = &lt;span style="color:#A31515;"&gt;&amp;quot;nextDouble&amp;quot;&lt;/span&gt;)]
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;double&lt;/span&gt; NextDouble()
    {
        &lt;span style="color:Blue;"&gt;return&lt;/span&gt; &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.random.NextDouble();
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Note the following:
&lt;ul&gt;&lt;li&gt;You need two classes - one is the constructor (i.e. the function object that you call new on) and one is for the instance object.&lt;/li&gt;
&lt;li&gt;The ClrFunction base class requires three parameters: the prototype for the function object, the name of the function and the prototype for any instances created using the function.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://jurassic.codeplex.com/wikipage?title=JSConstructorFunction&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;JSConstructorFunction&lt;/a&gt; attribute marks the method that is called when the &lt;b&gt;new&lt;/b&gt; operator is used.  You can also use &lt;a href="http://jurassic.codeplex.com/wikipage?title=JSCallFunction&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;JSCallFunction&lt;/a&gt; to mark the method that is called when the function is called directly.&lt;/li&gt;
&lt;li&gt;The RandomInstance class has two constructors - one is used to initialize the prototype, one is used to initialize all other instances.  &lt;b&gt;PopulateFunctions&lt;/b&gt; should only be called from the prototype object.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;Here&amp;#39;s an example of how to create and use the new class:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; engine = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Jurassic.ScriptEngine();
engine.SetGlobalValue(&lt;span style="color:#A31515;"&gt;&amp;quot;Random&amp;quot;&lt;/span&gt;, &lt;span style="color:Blue;"&gt;new&lt;/span&gt; RandomConstructor(engine));
Console.WriteLine(engine.Evaluate&amp;lt;&lt;span style="color:Blue;"&gt;double&lt;/span&gt;&amp;gt;(&lt;span style="color:#A31515;"&gt;&amp;quot;var rand = new Random(1000); rand.nextDouble()&amp;quot;&lt;/span&gt;));
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This will output &amp;quot;0.151557459100875&amp;quot; to the console (since we are using a seed, it will be the same every time).&lt;br /&gt;&lt;br /&gt;This example is much more involved, but it supports all of the advanced JavaScript concepts:
&lt;ul&gt;&lt;li&gt;&lt;i&gt;rand&lt;/i&gt; supports the built-in Object functions (hasOwnProperty, toString, etc).&lt;/li&gt;
&lt;li&gt;&lt;i&gt;rand&lt;/i&gt; utilizes prototypical inheritance.  In this case you have the following prototype chain: random instance (with no properties) -&amp;gt; random prototype (with nextDouble defined) -&amp;gt; object prototype -&amp;gt; null.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;br /&gt;Next tutorial: &lt;a href="http://jurassic.codeplex.com/wikipage?title=Loading%20a%20script%20from%20a%20custom%20source&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;Loading a script from a custom source&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>paulbartrum</author><pubDate>Sat, 07 Apr 2012 07:00:32 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Exposing a .NET class to JavaScript 20120407070032A</guid></item><item><title>Updated Wiki: Exposing a .NET class to JavaScript</title><link>http://jurassic.codeplex.com/wikipage?title=Exposing a .NET class to JavaScript&amp;version=7</link><description>&lt;div class="wikidoc"&gt;&lt;h2&gt;Exposing a .NET class to JavaScript&lt;/h2&gt;
&lt;h3&gt;Building a property bag class&lt;/h3&gt;
To start with, let&amp;#39;s create a class that contains a couple of properties.&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic.Library;

&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; AppInfo : ObjectInstance
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; AppInfo(ScriptEngine engine)
        : &lt;span style="color:Blue;"&gt;base&lt;/span&gt;(engine)
    {
        &lt;span style="color:Green;"&gt;// Read-write property (name).&lt;/span&gt;
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;[&lt;span style="color:#A31515;"&gt;&amp;quot;name&amp;quot;&lt;/span&gt;] = &lt;span style="color:#A31515;"&gt;&amp;quot;Test Application&amp;quot;&lt;/span&gt;;

        &lt;span style="color:Green;"&gt;// Read-only property (version).&lt;/span&gt;
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.DefineProperty(&lt;span style="color:#A31515;"&gt;&amp;quot;version&amp;quot;&lt;/span&gt;, &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PropertyDescriptor(5, PropertyAttributes.Sealed), &lt;span style="color:Blue;"&gt;true&lt;/span&gt;);
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;In this example there are a few things to note:
&lt;ul&gt;&lt;li&gt;Classes that are exposed to JavaScript are required to inherit from &lt;b&gt;Jurassic.Library.ObjectInstance&lt;/b&gt;.&lt;/li&gt;
&lt;li&gt;Passing a ScriptEngine to the base class constructor means that the object will have no prototype.  Therefore the usual functions (hasOwnProperty, toString) will not be available.&lt;/li&gt;
&lt;li&gt;The class indexer can be used to create read-write properties.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;DefineProperty&lt;/b&gt; can be used to create read-only properties.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;Here&amp;#39;s an example of how to create and use the new class:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; engine = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Jurassic.ScriptEngine();
engine.SetGlobalValue(&lt;span style="color:#A31515;"&gt;&amp;quot;appInfo&amp;quot;&lt;/span&gt;, &lt;span style="color:Blue;"&gt;new&lt;/span&gt; AppInfo(engine));
Console.WriteLine(engine.Evaluate&amp;lt;&lt;span style="color:Blue;"&gt;string&lt;/span&gt;&amp;gt;(&lt;span style="color:#A31515;"&gt;&amp;quot;appInfo.name + &amp;quot;&lt;/span&gt; &lt;span style="color:#A31515;"&gt;&amp;quot; + appInfo.version&amp;quot;&lt;/span&gt;));
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This will output &amp;quot;Test Application 5&amp;quot; to the console.&lt;br /&gt;&lt;br /&gt;
&lt;h3&gt;Building a class with static functions&lt;/h3&gt;
The next step up is to create a class with static functions, similar to how the built-in Math object works.  For example, say you want to create a new Math2 object with a log10 function:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic.Library;

&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; Math2 : ObjectInstance
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; Math2(ScriptEngine engine)
        : &lt;span style="color:Blue;"&gt;base&lt;/span&gt;(engine)
    {
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.PopulateFunctions();
    }

    [JSFunction(Name = &lt;span style="color:#A31515;"&gt;&amp;quot;log10&amp;quot;&lt;/span&gt;)]
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;static&lt;/span&gt; &lt;span style="color:Blue;"&gt;double&lt;/span&gt; Log10(&lt;span style="color:Blue;"&gt;double&lt;/span&gt; num)
    {
        &lt;span style="color:Blue;"&gt;return&lt;/span&gt; Math.Log10(num);
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Note the following:
&lt;ul&gt;&lt;li&gt;&lt;b&gt;PopulateFunctions&lt;/b&gt; searches the class for &lt;a href="http://jurassic.codeplex.com/wikipage?title=JSFunction&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;JSFunction&lt;/a&gt; attributes and creates a function for each one it finds.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://jurassic.codeplex.com/wikipage?title=JSFunction&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;JSFunction&lt;/a&gt; attributes allows the JavaScript function name to be different from the .NET method name.&lt;/li&gt;
&lt;li&gt;The parameter types and the return type must be on the list of &lt;a href="http://jurassic.codeplex.com/wikipage?title=Supported%20types&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;supported types&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Please note: This feature requires the latest build from source control and is not yet in the official Downloads&lt;/i&gt; Decorating a property with the &lt;a href="http://jurassic.codeplex.com/wikipage?title=JSProperty&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;JSProperty&lt;/a&gt; attribute allows properties to be exposed to script as accessors.  You can therefore code properties, complete with backers, in CLR, or make read-only properties in CLR code.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;Here&amp;#39;s an example of how to create and use the new class:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; engine = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Jurassic.ScriptEngine();
engine.SetGlobalValue(&lt;span style="color:#A31515;"&gt;&amp;quot;math2&amp;quot;&lt;/span&gt;, &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Math2(engine));
Console.WriteLine(engine.Evaluate&amp;lt;&lt;span style="color:Blue;"&gt;double&lt;/span&gt;&amp;gt;(&lt;span style="color:#A31515;"&gt;&amp;quot;math2.log10(1000)&amp;quot;&lt;/span&gt;));
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This will output &amp;quot;3&amp;quot; to the console.&lt;br /&gt;&lt;br /&gt;
&lt;h3&gt;Building an instance class&lt;/h3&gt;
Objects that can be instantiated, like the built-in Number, String, Array and RegExp objects, require two .NET classes, one for the constructor and one for the instance.  For example, let&amp;#39;s make a JavaScript object that works similar to the .NET Random class (with a seed, since JavaScript doesn&amp;#39;t support this):&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic.Library;

&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; RandomConstructor : ClrFunction
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; RandomConstructor(ScriptEngine engine)
        : &lt;span style="color:Blue;"&gt;base&lt;/span&gt;(engine.Function.InstancePrototype, &lt;span style="color:#A31515;"&gt;&amp;quot;Random&amp;quot;&lt;/span&gt;, &lt;span style="color:Blue;"&gt;new&lt;/span&gt; RandomInstance(engine.Object.InstancePrototype))
    {
    }

    [JSConstructorFunction]
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; RandomInstance Construct(&lt;span style="color:Blue;"&gt;int&lt;/span&gt; seed)
    {
        &lt;span style="color:Blue;"&gt;return&lt;/span&gt; &lt;span style="color:Blue;"&gt;new&lt;/span&gt; RandomInstance(&lt;span style="color:Blue;"&gt;this&lt;/span&gt;.InstancePrototype, seed);
    }
}

&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; RandomInstance : ObjectInstance
{
    &lt;span style="color:Blue;"&gt;private&lt;/span&gt; Random random;

    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; RandomInstance(ObjectInstance prototype)
        : &lt;span style="color:Blue;"&gt;base&lt;/span&gt;(prototype)
    {
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.PopulateFunctions();
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.random = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Random(0);
    }

    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; RandomInstance(ObjectInstance prototype, &lt;span style="color:Blue;"&gt;int&lt;/span&gt; seed)
        : &lt;span style="color:Blue;"&gt;base&lt;/span&gt;(prototype)
    {
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.random = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Random(seed);
    }

    [JSFunction(Name = &lt;span style="color:#A31515;"&gt;&amp;quot;nextDouble&amp;quot;&lt;/span&gt;)]
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;double&lt;/span&gt; NextDouble()
    {
        &lt;span style="color:Blue;"&gt;return&lt;/span&gt; &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.random.NextDouble();
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Note the following:
&lt;ul&gt;&lt;li&gt;You need two classes - one is the constructor (i.e. the function object that you call new on) and one is for the instance object.&lt;/li&gt;
&lt;li&gt;The ClrFunction base class requires three parameters: the prototype for the function object, the name of the function and the prototype for any instances created using the function.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://jurassic.codeplex.com/wikipage?title=JSConstructorFunction&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;JSConstructorFunction&lt;/a&gt; attribute marks the method that is called when the &lt;b&gt;new&lt;/b&gt; operator is used.  You can also use &lt;a href="http://jurassic.codeplex.com/wikipage?title=JSCallFunction&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;JSCallFunction&lt;/a&gt; to mark the method that is called when the function is called directly.&lt;/li&gt;
&lt;li&gt;The RandomInstance class has two constructors - one is used to initialize the prototype, one is used to initialize all other instances.  &lt;b&gt;PopulateFunctions&lt;/b&gt; should only be called from the prototype object.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;Here&amp;#39;s an example of how to create and use the new class:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; engine = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Jurassic.ScriptEngine();
engine.SetGlobalValue(&lt;span style="color:#A31515;"&gt;&amp;quot;Random&amp;quot;&lt;/span&gt;, &lt;span style="color:Blue;"&gt;new&lt;/span&gt; RandomConstructor(engine));
Console.WriteLine(engine.Evaluate&amp;lt;&lt;span style="color:Blue;"&gt;double&lt;/span&gt;&amp;gt;(&lt;span style="color:#A31515;"&gt;&amp;quot;var rand = new Random(1000); rand.nextDouble()&amp;quot;&lt;/span&gt;));
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This will output &amp;quot;0.151557459100875&amp;quot; to the console (since we are using a seed, it will be the same every time).&lt;br /&gt;&lt;br /&gt;This example is much more involved, but it supports all of the advanced JavaScript concepts:
&lt;ul&gt;&lt;li&gt;&lt;i&gt;rand&lt;/i&gt; supports the built-in Object functions (hasOwnProperty, toString, etc).&lt;/li&gt;
&lt;li&gt;&lt;i&gt;rand&lt;/i&gt; utilizes prototypical inheritance.  In this case you have the following prototype chain: random instance (with no properties) -&amp;gt; random prototype (with nextDouble defined) -&amp;gt; object prototype -&amp;gt; null.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;br /&gt;Next tutorial: &lt;a href="http://jurassic.codeplex.com/wikipage?title=Loading%20a%20script%20from%20a%20custom%20source&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;Loading a script from a custom source&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>paulbartrum</author><pubDate>Sat, 07 Apr 2012 07:00:05 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Exposing a .NET class to JavaScript 20120407070005A</guid></item><item><title>Updated Wiki: Exposing a .NET class to JavaScript</title><link>http://jurassic.codeplex.com/wikipage?title=Exposing a .NET class to JavaScript&amp;version=6</link><description>&lt;div class="wikidoc"&gt;&lt;h2&gt;Exposing a .NET class to JavaScript&lt;/h2&gt;
&lt;h3&gt;Building a property bag class&lt;/h3&gt;
To start with, let&amp;#39;s create a class that contains a couple of properties.&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic.Library;

&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; AppInfo : ObjectInstance
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; AppInfo(ScriptEngine engine)
        : &lt;span style="color:Blue;"&gt;base&lt;/span&gt;(engine)
    {
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;[&lt;span style="color:#A31515;"&gt;&amp;quot;name&amp;quot;&lt;/span&gt;] = &lt;span style="color:#A31515;"&gt;&amp;quot;Test Application&amp;quot;&lt;/span&gt;;
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;[&lt;span style="color:#A31515;"&gt;&amp;quot;version&amp;quot;&lt;/span&gt;] = 5;
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;In this example there are a few things to note:
&lt;ul&gt;&lt;li&gt;Classes that are exposed to JavaScript are required to inherit from &lt;b&gt;Jurassic.Library.ObjectInstance&lt;/b&gt;.&lt;/li&gt;
&lt;li&gt;Passing a ScriptEngine to the base class constructor means that the object will have no prototype.  Therefore the usual functions (hasOwnProperty, toString) will not be available.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;DefineProperty&lt;/b&gt; is used to create read-only properties.  &lt;b&gt;SetPropertyValue&lt;/b&gt; is simpler, but only creates read-write properties.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;Here&amp;#39;s an example of how to create and use the new class:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; engine = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Jurassic.ScriptEngine();
engine.SetGlobalValue(&lt;span style="color:#A31515;"&gt;&amp;quot;appInfo&amp;quot;&lt;/span&gt;, &lt;span style="color:Blue;"&gt;new&lt;/span&gt; AppInfo(engine));
Console.WriteLine(engine.Evaluate&amp;lt;&lt;span style="color:Blue;"&gt;string&lt;/span&gt;&amp;gt;(&lt;span style="color:#A31515;"&gt;&amp;quot;appInfo.name + &amp;quot;&lt;/span&gt; &lt;span style="color:#A31515;"&gt;&amp;quot; + appInfo.version&amp;quot;&lt;/span&gt;));
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This will output &amp;quot;Test Application 5&amp;quot; to the console.&lt;br /&gt;&lt;br /&gt;
&lt;h3&gt;Building a class with static functions&lt;/h3&gt;
The next step up is to create a class with static functions, similar to how the built-in Math object works.  For example, say you want to create a new Math2 object with a log10 function:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic.Library;

&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; Math2 : ObjectInstance
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; Math2(ScriptEngine engine)
        : &lt;span style="color:Blue;"&gt;base&lt;/span&gt;(engine)
    {
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.PopulateFunctions();
    }

    [JSFunction(Name = &lt;span style="color:#A31515;"&gt;&amp;quot;log10&amp;quot;&lt;/span&gt;)]
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;static&lt;/span&gt; &lt;span style="color:Blue;"&gt;double&lt;/span&gt; Log10(&lt;span style="color:Blue;"&gt;double&lt;/span&gt; num)
    {
        &lt;span style="color:Blue;"&gt;return&lt;/span&gt; Math.Log10(num);
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Note the following:
&lt;ul&gt;&lt;li&gt;&lt;b&gt;PopulateFunctions&lt;/b&gt; searches the class for &lt;a href="http://jurassic.codeplex.com/wikipage?title=JSFunction&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;JSFunction&lt;/a&gt; attributes and creates a function for each one it finds.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://jurassic.codeplex.com/wikipage?title=JSFunction&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;JSFunction&lt;/a&gt; attributes allows the JavaScript function name to be different from the .NET method name.&lt;/li&gt;
&lt;li&gt;The parameter types and the return type must be on the list of &lt;a href="http://jurassic.codeplex.com/wikipage?title=Supported%20types&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;supported types&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Please note: This feature requires the latest build from source control and is not yet in the official Downloads&lt;/i&gt; Decorating a property with the &lt;a href="http://jurassic.codeplex.com/wikipage?title=JSProperty&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;JSProperty&lt;/a&gt; attribute allows properties to be exposed to script as accessors.  You can therefore code properties, complete with backers, in CLR, or make read-only properties in CLR code.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;Here&amp;#39;s an example of how to create and use the new class:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; engine = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Jurassic.ScriptEngine();
engine.SetGlobalValue(&lt;span style="color:#A31515;"&gt;&amp;quot;math2&amp;quot;&lt;/span&gt;, &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Math2(engine));
Console.WriteLine(engine.Evaluate&amp;lt;&lt;span style="color:Blue;"&gt;double&lt;/span&gt;&amp;gt;(&lt;span style="color:#A31515;"&gt;&amp;quot;math2.log10(1000)&amp;quot;&lt;/span&gt;));
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This will output &amp;quot;3&amp;quot; to the console.&lt;br /&gt;&lt;br /&gt;
&lt;h3&gt;Building an instance class&lt;/h3&gt;
Objects that can be instantiated, like the built-in Number, String, Array and RegExp objects, require two .NET classes, one for the constructor and one for the instance.  For example, let&amp;#39;s make a JavaScript object that works similar to the .NET Random class (with a seed, since JavaScript doesn&amp;#39;t support this):&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; Jurassic.Library;

&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; RandomConstructor : ClrFunction
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; RandomConstructor(ScriptEngine engine)
        : &lt;span style="color:Blue;"&gt;base&lt;/span&gt;(engine.Function.InstancePrototype, &lt;span style="color:#A31515;"&gt;&amp;quot;Random&amp;quot;&lt;/span&gt;, &lt;span style="color:Blue;"&gt;new&lt;/span&gt; RandomInstance(engine.Object.InstancePrototype))
    {
    }

    [JSConstructorFunction]
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; RandomInstance Construct(&lt;span style="color:Blue;"&gt;int&lt;/span&gt; seed)
    {
        &lt;span style="color:Blue;"&gt;return&lt;/span&gt; &lt;span style="color:Blue;"&gt;new&lt;/span&gt; RandomInstance(&lt;span style="color:Blue;"&gt;this&lt;/span&gt;.InstancePrototype, seed);
    }
}

&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; RandomInstance : ObjectInstance
{
    &lt;span style="color:Blue;"&gt;private&lt;/span&gt; Random random;

    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; RandomInstance(ObjectInstance prototype)
        : &lt;span style="color:Blue;"&gt;base&lt;/span&gt;(prototype)
    {
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.PopulateFunctions();
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.random = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Random(0);
    }

    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; RandomInstance(ObjectInstance prototype, &lt;span style="color:Blue;"&gt;int&lt;/span&gt; seed)
        : &lt;span style="color:Blue;"&gt;base&lt;/span&gt;(prototype)
    {
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.random = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Random(seed);
    }

    [JSFunction(Name = &lt;span style="color:#A31515;"&gt;&amp;quot;nextDouble&amp;quot;&lt;/span&gt;)]
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;double&lt;/span&gt; NextDouble()
    {
        &lt;span style="color:Blue;"&gt;return&lt;/span&gt; &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.random.NextDouble();
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Note the following:
&lt;ul&gt;&lt;li&gt;You need two classes - one is the constructor (i.e. the function object that you call new on) and one is for the instance object.&lt;/li&gt;
&lt;li&gt;The ClrFunction base class requires three parameters: the prototype for the function object, the name of the function and the prototype for any instances created using the function.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://jurassic.codeplex.com/wikipage?title=JSConstructorFunction&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;JSConstructorFunction&lt;/a&gt; attribute marks the method that is called when the &lt;b&gt;new&lt;/b&gt; operator is used.  You can also use &lt;a href="http://jurassic.codeplex.com/wikipage?title=JSCallFunction&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;JSCallFunction&lt;/a&gt; to mark the method that is called when the function is called directly.&lt;/li&gt;
&lt;li&gt;The RandomInstance class has two constructors - one is used to initialize the prototype, one is used to initialize all other instances.  &lt;b&gt;PopulateFunctions&lt;/b&gt; should only be called from the prototype object.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;Here&amp;#39;s an example of how to create and use the new class:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; engine = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Jurassic.ScriptEngine();
engine.SetGlobalValue(&lt;span style="color:#A31515;"&gt;&amp;quot;Random&amp;quot;&lt;/span&gt;, &lt;span style="color:Blue;"&gt;new&lt;/span&gt; RandomConstructor(engine));
Console.WriteLine(engine.Evaluate&amp;lt;&lt;span style="color:Blue;"&gt;double&lt;/span&gt;&amp;gt;(&lt;span style="color:#A31515;"&gt;&amp;quot;var rand = new Random(1000); rand.nextDouble()&amp;quot;&lt;/span&gt;));
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This will output &amp;quot;0.151557459100875&amp;quot; to the console (since we are using a seed, it will be the same every time).&lt;br /&gt;&lt;br /&gt;This example is much more involved, but it supports all of the advanced JavaScript concepts:
&lt;ul&gt;&lt;li&gt;&lt;i&gt;rand&lt;/i&gt; supports the built-in Object functions (hasOwnProperty, toString, etc).&lt;/li&gt;
&lt;li&gt;&lt;i&gt;rand&lt;/i&gt; utilizes prototypical inheritance.  In this case you have the following prototype chain: random instance (with no properties) -&amp;gt; random prototype (with nextDouble defined) -&amp;gt; object prototype -&amp;gt; null.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;br /&gt;Next tutorial: &lt;a href="http://jurassic.codeplex.com/wikipage?title=Loading%20a%20script%20from%20a%20custom%20source&amp;referringTitle=Exposing%20a%20.NET%20class%20to%20JavaScript"&gt;Loading a script from a custom source&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>paulbartrum</author><pubDate>Sat, 07 Apr 2012 06:57:44 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Exposing a .NET class to JavaScript 20120407065744A</guid></item><item><title>New Comment on "Future plans"</title><link>http://jurassic.codeplex.com/wikipage?title=Future plans&amp;ANCHOR#C22468</link><description>1&amp;#41; An debug api to step into, step out &amp;#40;execute line by line&amp;#41;, get source line, inspect variable, run, stop. This allow an aplication to emulate an debugger &amp;#40;see remobjects.com, they already do that in their javascript engine&amp;#41;&amp;#10;&amp;#10;2&amp;#41; Ability to generate an DLL file from js, to posterior use with Engine &amp;#40;like Engine.ExecutePrecompiledJavascriptDll &amp;#40;&amp;#34;mydll.dll&amp;#34;&amp;#41;&amp;#59; that skip parse, and compile and optimization stages and executes directly, speeding execution&amp;#59;&amp;#10;&amp;#10;3&amp;#41; Make ToJSDate public&amp;#10;&amp;#10;4&amp;#41; Implement SetTimeOut, SetInterval and WebWorker&amp;#10;&amp;#10;5&amp;#41; Implement XMLHttpRequest object&amp;#10;&amp;#10;6&amp;#41; Integrate DynamicObjectWraper directly inside of Objectinstance &amp;#40;Only when Jurassic nevermore support Net 3.5&amp;#41;&amp;#10;&amp;#10;7&amp;#41; Implement Typed Array, and Binary types, like Int64 - http&amp;#58;&amp;#47;&amp;#47;www.khronos.org&amp;#47;registry&amp;#47;typedarray&amp;#47;specs&amp;#47;latest&amp;#47;&amp;#10;&amp;#10;this will permit usage of Jurassic with WEBGL, 3d graphic aplications and the usage of Jurassic with databases that have biginteger fields.&amp;#10;&amp;#10;8&amp;#41; An visual Studio debug PlugIn&amp;#10;May be http&amp;#58;&amp;#47;&amp;#47;msdn.microsoft.com&amp;#47;en-us&amp;#47;library&amp;#47;bb161694&amp;#40;v&amp;#61;vs.80&amp;#41;.aspx help to implement this.</description><author>cmcbf</author><pubDate>Mon, 06 Feb 2012 00:21:21 GMT</pubDate><guid isPermaLink="false">New Comment on "Future plans" 20120206122121A</guid></item><item><title>New Comment on "Future plans"</title><link>http://jurassic.codeplex.com/wikipage?title=Future plans&amp;ANCHOR#C22467</link><description>1&amp;#41; An debug api to step into, step out &amp;#40;execute line by line&amp;#41;, get source line, inspect variable, run, stop. This allow an aplication to emulate an debugger &amp;#40;see remobjects.com, they already do that in their javascript engine&amp;#41;&amp;#10;&amp;#10;2&amp;#41; Ability to generate an DLL file from js, to posterior use with Engine &amp;#40;like Engine.ExecutePrecompiledJavascriptDll &amp;#40;&amp;#34;mydll.dll&amp;#34;&amp;#41;&amp;#59; that skip parse, and compile and optimization  stages and executes directly, speeding execution&amp;#59;&amp;#10;&amp;#10;3&amp;#41; Make ToJSDate public&amp;#10;&amp;#10;4&amp;#41; Implement SetTimeOut, SetInterval and WebWorker&amp;#10;&amp;#10;5&amp;#41; Implement XMLHttpRequest object&amp;#10;&amp;#10;6&amp;#41; an option to ScriptEngine to register Global Object as window by default&amp;#10;Like engine.TreatGlobalObjectAsWindow &amp;#61; true&amp;#59; &amp;#10;&amp;#10;7&amp;#41; Integrate DynamicObjectWraper directly inside of Objectinstance &amp;#40;Only when Jurassic nevermore support Net 3.5&amp;#41;&amp;#10;&amp;#10;8&amp;#41; Implement Typed Array, and Binary types, like Int64 -  http&amp;#58;&amp;#47;&amp;#47;www.khronos.org&amp;#47;registry&amp;#47;typedarray&amp;#47;specs&amp;#47;latest&amp;#47;&amp;#10;&amp;#10;this will permit usage of Jurassic with WEBGL, 3d graphic aplications and the usage of Jurassic with databases that have biginteger fields.&amp;#10;&amp;#10;9&amp;#41; An visual Studio debug PlugIn&amp;#10;May be http&amp;#58;&amp;#47;&amp;#47;msdn.microsoft.com&amp;#47;en-us&amp;#47;library&amp;#47;bb161694&amp;#40;v&amp;#61;vs.80&amp;#41;.aspx help to implement this.</description><author>cmcbf</author><pubDate>Mon, 06 Feb 2012 00:19:18 GMT</pubDate><guid isPermaLink="false">New Comment on "Future plans" 20120206121918A</guid></item><item><title>New Comment on "Debugging"</title><link>http://jurassic.codeplex.com/wikipage?title=Debugging&amp;ANCHOR#C22440</link><description>&amp;#64;paulbartrum -&amp;#58; hummmm. To hard to implement. The MSDN documentation is very extense and dificult to understand....</description><author>cmcbf</author><pubDate>Fri, 03 Feb 2012 14:31:50 GMT</pubDate><guid isPermaLink="false">New Comment on "Debugging" 20120203023150P</guid></item><item><title>New Comment on "Debugging"</title><link>http://jurassic.codeplex.com/wikipage?title=Debugging&amp;ANCHOR#C22439</link><description>&amp;#64;pau -&amp;#58; hummmm. To hard to implement. The MSDN documentation is very extense and dificult to understand.... &amp;#10;&amp;#10;Thanks paul.</description><author>cmcbf</author><pubDate>Fri, 03 Feb 2012 14:30:54 GMT</pubDate><guid isPermaLink="false">New Comment on "Debugging" 20120203023054P</guid></item><item><title>New Comment on "Future plans"</title><link>http://jurassic.codeplex.com/wikipage?title=Future plans&amp;ANCHOR#C22436</link><description>1&amp;#41; An debug api to step into, step out &amp;#40;execute line by line&amp;#41;, get source line, inspect variable, run, stop. This allow an aplication to emulate an debugger &amp;#40;see remobjects.com, they already do that in their javascript engine&amp;#41;&amp;#10;&amp;#10;2&amp;#41; Ability to generate an DLL file from js, to posterior use with Engine &amp;#40;like Engine.ExecutePrecompiledJavascriptDll &amp;#40;&amp;#34;mydll.dll&amp;#34;&amp;#41;&amp;#59; and speed execution&amp;#59;&amp;#10;&amp;#10;3&amp;#41; Make ToJSDate public&amp;#10;&amp;#10;4&amp;#41; Implement SetTimeOut, SetInterval and WebWorker&amp;#10;&amp;#10;5&amp;#41; Implement XMLHttpRequest object&amp;#10;&amp;#10;6&amp;#41; an option to ScriptEngine to register Global Object as window by default&amp;#10;Like engine.TreatGlobalObjectAsWindow &amp;#61; true&amp;#59; &amp;#10;&amp;#10;7&amp;#41; Integrate DynamicObjectWraper directly inside of Objectinstance &amp;#40;Only when Jurassic nevermore support Net 3.5&amp;#41;&amp;#10;&amp;#10;8&amp;#41; Implement Typed Array, and Binary types, like Int64&amp;#10;&amp;#10;this will permit usage of Jurassic with WEBGL, 3d graphic aplications and the usage of Jurassic with databases that have biginteger fields.&amp;#10;&amp;#10;9&amp;#41; An visual Studio debug PlugIn&amp;#10;May be http&amp;#58;&amp;#47;&amp;#47;msdn.microsoft.com&amp;#47;en-us&amp;#47;library&amp;#47;bb161694&amp;#40;v&amp;#61;vs.80&amp;#41;.aspx help to implement this.</description><author>cmcbf</author><pubDate>Fri, 03 Feb 2012 13:26:35 GMT</pubDate><guid isPermaLink="false">New Comment on "Future plans" 20120203012635P</guid></item><item><title>New Comment on "Future plans"</title><link>http://jurassic.codeplex.com/wikipage?title=Future plans&amp;ANCHOR#C22435</link><description>some ideas&amp;#58;&amp;#10;&amp;#10;1&amp;#41; An debug api to step into, step out &amp;#40;execute line by line&amp;#41;, get source line, inspect variable, run, stop. This allow an aplication to emulate an debugger &amp;#40;see remobjects.com, they already do that in their javascript engine&amp;#41;&amp;#10;&amp;#10;2&amp;#41; Ability to generate an DLL file from js, to posterior use with Engine &amp;#40;like Engine.ExecutePrecompiledJavascriptDll &amp;#40;&amp;#34;mydll.dll&amp;#34;&amp;#41;&amp;#59; and speed execution&amp;#59;&amp;#10;&amp;#10;4&amp;#41; Make ToJSDate public&amp;#10;&amp;#10;5&amp;#41; Implement SetTimeOut, SetInterval and WebWorker&amp;#10;&amp;#10;6&amp;#41; Implement XMLHttpRequest object&amp;#10;&amp;#10;7&amp;#41; an option to ScriptEngine to register Global Object as window by default&amp;#10;   Like engine.TreatGlobalObjectAsWindow &amp;#61; true&amp;#59; &amp;#10;&amp;#10;7&amp;#41; Integrate DynamicObjectWraper directly inside of Objectinstance &amp;#40;Only when Jurassic nevermore  support Net 3.5&amp;#41;&amp;#10;&amp;#10;8&amp;#41; Implement Typed Array, and Binary types, like Int64&amp;#10;&amp;#10;this will permit usage of Jurassic with WEBGL, 3d graphic aplications and the usage of Jurassic with databases that have biginteger fields.&amp;#10;&amp;#10;9&amp;#41; An visual Studio debug PlugIn&amp;#10;    May be http&amp;#58;&amp;#47;&amp;#47;msdn.microsoft.com&amp;#47;en-us&amp;#47;library&amp;#47;bb161694&amp;#40;v&amp;#61;vs.80&amp;#41;.aspx help to implement this.</description><author>cmcbf</author><pubDate>Fri, 03 Feb 2012 13:25:37 GMT</pubDate><guid isPermaLink="false">New Comment on "Future plans" 20120203012537P</guid></item><item><title>New Comment on "Debugging"</title><link>http://jurassic.codeplex.com/wikipage?title=Debugging&amp;ANCHOR#C22424</link><description>&amp;#64;cmcbf - if only it was that easy&amp;#33;  To make this work, you actually have to write an expression evaluator, which is documented here&amp;#58; http&amp;#58;&amp;#47;&amp;#47;msdn.microsoft.com&amp;#47;en-us&amp;#47;library&amp;#47;bb161694.aspx</description><author>paulbartrum</author><pubDate>Thu, 02 Feb 2012 22:51:33 GMT</pubDate><guid isPermaLink="false">New Comment on "Debugging" 20120202105133P</guid></item><item><title>New Comment on "Debugging"</title><link>http://jurassic.codeplex.com/wikipage?title=Debugging&amp;ANCHOR#C22420</link><description>May be this article help to add visual debug support &amp;#10;&amp;#10;I think IL generation needs to add these atributes described in article.&amp;#10;&amp;#10;See http&amp;#58;&amp;#47;&amp;#47;msdn.microsoft.com&amp;#47;en-us&amp;#47;magazine&amp;#47;cc163974.aspx&amp;#10;&amp;#10;Also I modified FirebugConsole to suport output to Visual Studio Debug Console,&amp;#10;see http&amp;#58;&amp;#47;&amp;#47;jurassic.codeplex.com&amp;#47;discussions&amp;#47;289027</description><author>cmcbf</author><pubDate>Thu, 02 Feb 2012 15:04:13 GMT</pubDate><guid isPermaLink="false">New Comment on "Debugging" 20120202030413P</guid></item><item><title>New Comment on "Debugging"</title><link>http://jurassic.codeplex.com/wikipage?title=Debugging&amp;ANCHOR#C22419</link><description>http&amp;#58;&amp;#47;&amp;#47;msdn.microsoft.com&amp;#47;en-us&amp;#47;magazine&amp;#47;cc163974.aspx</description><author>cmcbf</author><pubDate>Thu, 02 Feb 2012 15:01:09 GMT</pubDate><guid isPermaLink="false">New Comment on "Debugging" 20120202030109P</guid></item></channel></rss>