visual studio javascript intellisense friendly
// enum creation pattern
// NOTE: i am not doing the intensive argument validation
// and restricting the enum values to integer as is done in
// msajax so you can probably break this with little effort.
function createEnum(type, flags)
{
for (var i in type.prototype)
{
type[i] = type.prototype[i];
}
// __xxx props are msajax/vs talking to each other
type.__enum = true;
type.__flags = flags;
}
intEnum = function()
{
/// <summary>
/// intEnum - standard enum type
/// </summary>
/// <field name="add" type="Number" integer="true" static="true" >add</field>
/// <field name="remove" type="Number" integer="true" static="true">remove</field>
/// <field name="reset" type="Number" integer="true" static="true" >reset</field>
throw new Error("constructor not implemented. this is a static enum");
}
intEnum.prototype = {
add: 0,
remove: 1,
reset: 2
}
createEnum(intEnum);
stringEnum = function()
{
/// <summary>
/// stringEnum - interesting - a string constant enum.
/// something I have always wanted in clr code
/// </summary>
/// <field name="add" type="String" static="true" >add</field>
/// <field name="remove" type="String" static="true">remove</field>
/// <field name="reset" type="String" static="true" >reset</field>
throw new Error("constructor not implemented. this is a static enum");
}
stringEnum.prototype = {
add: "add",
remove: "remove",
reset: "reset"
}
createEnum(stringEnum);
// vs intellisense works as it evaluates referenced scripts in the background
// so you will not see the fruits of this labor while in the file
// that the enums are declared in. Go to the html page or to another script that
// has a /// <reference path="xxx.js" /> tag at the top , press ctrl+alt+j to
// update intellisense and bingo -you have enums and pretty intellisense visual
// cues.
Technorati tags:
Visual Studio,
JavaScript,
Intellisense,
CodeProject-Tip