Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Can not use prototype declarations with V8 Engine

$
0
0
Hi.

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))
                {
                    engine.Execute(reader.ReadToEnd());
                }
           }
The JS code is (sample.js embedded resource):
var System = Environment.System;
var Console = System.Console;
var Car = (function () {
    function Car(logger, settings) {
    }

    Car.prototype.bar = 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!

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images