This project has moved. For the latest updates, please go here.

Can not use prototype declarations with V8 Engine

Nov 21, 2013 at 7:14 PM

I've tried to create a simple "class" declaration using prototype declarations and it seems like that V8 engine don't support that.

The C# code is:
using (var engine = new JScriptEngine())
                /* Attach the host functions */
                engine.AddHostObject("host", new HostFunctions());
                engine.AddHostObject("Environment", new HostTypeCollection("mscorlib", "System.Core"));
                var assembly = System.Reflection.Assembly.GetExecutingAssembly();
                using (var stream = assembly.GetManifestResourceStream("ClearScriptTests.Scripts.sample.js"))
                using (var reader = new System.IO.StreamReader(stream))
The JS code is (sample.js embedded resource):
var System = Environment.System;
var Console = System.Console;
var Car = (function () {
    function Car(logger, settings) {
    } = function () { Console.WriteLine("bar"); }
for (var m in Car) {
    Console.WriteLine("Property: " + m);
When I'm changing the engine from V8ScriptEngine to JScriptEngine the code works pefectly. I cane across this when trying to use TypeScript, which uses prototypes too.

Thanks for any feedback!
Nov 22, 2013 at 2:03 AM
Hello yahavgb!

We tested your code and got the same results with both script engines: Car is undefined and no output is generated. That makes sense because the code sets Car (the outer one) to the return value of a function that lacks a return statement.

What results are you seeing?