-
Notifications
You must be signed in to change notification settings - Fork 1
Usage
dotnetwise edited this page Mar 25, 2013
·
13 revisions
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.
- By using the
namespace
(aliasns
) 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
- Your own manual code
window.MyApp = window.MyApp || {};
MyApp.__namespace = true;
MyApp.controllers = MyApp.controllers || {};
MyApp.__namespace = true;
- 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
- Your own manual code
var countries = {Romania: 1, USA: 2, Germany: 3, Spain: 4, Netherlands: 5};
countries.__enum = true; // enables the enum glyph
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
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