create class with prototype

Nov 10, 2013 at 11:25 AM
hi i have this code:
function gui() {}
gui.prototype.window = function (title) {
    var f = new Form();
    f.Text = title;
    
    return f;
}
but it doesnt work:
Object does not support this property or method.
Coordinator
Nov 10, 2013 at 3:55 PM
Hello furesoft!

Can you give us some more context? How are you setting up the script engine? How are you executing the JavaScript code? Where exactly are you seeing the exception?

Here's a simple example app that includes your code and works correctly:
using System.Windows.Forms;
using Microsoft.ClearScript.Windows;

namespace Test
{
    internal static class TestApp
    {
        public static void Main()
        {
            using (var engine = new JScriptEngine())
            {
                engine.AddHostType("Application", typeof(Application));
                engine.AddHostType("Form", typeof(Form));
                engine.Execute(@"
                    function gui() {}
                    gui.prototype.window = function (title) {
                        var f = new Form();
                        f.Text = title;
                        return f;
                    }
                    var myGui = new gui();
                    Application.Run(myGui.window('Hello'));
                ");
            }
        }
    }
}
Please let us know if this differs significantly from your scenario.

Thanks!