
Security News
Deno 2.4 Brings Back deno bundle, Improves Dependency Management and Observability
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Simple Enumerable object in javascript.
Enum.extend function expect two parameters:
var HTTPCodeEnum = Enum.extend({
CONTINUE: "100",
OK: "200",
MULTIPLE_CHOISES: "300",
BAD_REQUEST: "400",
INTERNAL_ERROR: "500"
});
You can also pass in first object:
MyEnum.myFunction()
__myInternalValue
Enum throws error in some usual cases. So there is an ability to use custom Errors for your custom Enums, to catch them upper and check with instanceOf
function:
var HTTPCodeEnum = Enum.extend({
... // constants
__error: MyOwnError // reference to your Error constructor
});
If
__error
does not present in first parameter object, then Enum will use its own EnumError constructor. Anyway, u can always get the reference to the Error function viaEnum.__error
function ajaxCallback(data) {
if (data.code == HTTPCodeEnum.OK) {
// ...
}
}
function ajaxCallback(data) {
// Throws a EnumError if catch non existing code
var status = new HTTPCodeEnum(data.code);
// Returns mapped message
// getMessage must be implemented in HTTPCodeEnum.prototype
console.log(status.getMessage());
}
// Exceptions handling
function indexController() {
try {
var request = $.ajax(...).done(ajaxCallback);
} catch(e) {
if (e instanceof HTTPCodeEnum.__error) {
console.log('Catched non existing HTTP code!', e.message);
}
}
}
FAQs
Javascript enum object
The npm package enum-js receives a total of 7 weekly downloads. As such, enum-js popularity was classified as not popular.
We found that enum-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.