0

I am new to Windows 8 development, my question is: how do I use C# Singleton in Javascript app? I am using the Static Initialization (http://msdn.microsoft.com/en-us/library/ff650316.aspx) in my C# class. MyClass.Instance (which returns the singleton instance) is undefined when I call it in Javascript. Thanks.

EDIT: I have a C# class which is Singleton, and I am trying to use it with my Javascript Windows 8 App, I am not trying to implement Singleton in Javascript.

Yifan Zhang
  • 321
  • 1
  • 4
  • 12
  • Check out this: http://stackoverflow.com/questions/1635800/javascript-best-singleton-pattern – JAM May 11 '13 at 19:28
  • this is not what I am looking for. I am trying to use C# singleton class in javascript. I don't even know if it is possible. – Yifan Zhang May 12 '13 at 09:13

1 Answers1

0

Language projection will slightly change the name of properties to conform to the patterns used in the consuming language. So when you define a property MyClass::Instance in C#, you should have MyClass.instance (lowercase 'i') in JavaScript.

Also, you can browse the available functions and properties in the JavaScript debugger (using Shift+F9 and entering "MyClass" for example is one way).

Marcus Ilgner
  • 6,935
  • 2
  • 30
  • 44