Skip to content
dotnetwise edited this page Mar 25, 2013 · 13 revisions

Files

There are two files coming with this library. _vs2012.intallisense.js and NamespacesAndEnumSupport.js

You only need to include NamespacesAndEnumSupport.js in your code if you want to use the utilities namespace, ns or Enum so you won't get a runtime error in your javascript.

Utilities

Defining a namespace Namespace

  1. By using the namespace (alias ns) method
namespace("MyApp.controllers") // defines MyApp.controllers nested namespaces in window
ns("mvvm.invoicing", MyApp)    // defines MyApp.mvvm.invoicing namespaces by specifying where to store them
ns("a/b/c/d", window, "/")     // defines namespaces a.b.c.d by using a custom separator
  1. Your own manual code
window.MyApp = window.MyApp || {};
MyApp.__namespace = true;
MyApp.controllers = MyApp.controllers || {};
MyApp.__namespace = true;

Defining an enum Enum

  1. By using the Enum function
var countries = new Enum({Romania: 1, USA: 2, Germany: 3, Spain: 4, Netherlands: 5}) // defines an enum with some countries
var plants = new Enum({Flower: "flower", Tree: "tree", Cereal: "seed"})              // defines an enum with string values
  1. Your own manual code
var countries = {Romania: 1, USA: 2, Germany: 3, Spain: 4, Netherlands: 5};
countries.__enum = true;                                                             // enables the enum glyph

Explicit options

You can set any of these on your objects/functions accordingly:

  • __namespace = true - makes an object to look like a namespace
  • __class = true - makes an function to look like a class
  • __enum = true - makes an object to look like an enum
  • __interface = true - makes a function to look like an interface
  • __map = true - makes an object to look like a dictionary
  • __const = true - makes an object to look like a constant
  • __event = true - makes an object to look like an event
  • __delegate = true - makes a function to look like a delegate

Implicit options

Besides the explicit setting of the above options, following rules apply:

  • Anything named on**** will be considered an event
  • Anything named with an Uppercase letter will be considered a Class
  • Fields will automatically be declared by their current value type i.e.
  • Number
  • Boolean
  • String
  • RegExp
  • null
  • undefined
  • Anything named constructor is always considered a Class
  • Methods defined on Object.prototype have specific glyph icon
  • Methods defined on custom .prototype have specific glyph icon (like an external method)
  • Keyword prototype has a specific glyph icon
  • Any DOM element will be automatically detected and have specific glyph icon
Clone this wiki locally