rauschma / enums Goto Github PK
View Code? Open in Web Editor NEWA simple enum implementation for JavaScript
License: MIT License
A simple enum implementation for JavaScript
License: MIT License
A simple enum implementation for JavaScript =========================================== Usage example ------------- var color = new enums.Enum("red", "green", "blue"); function isGreen(c) { return c === color.green; } Details: http://www.2ality.com/2011/10/enums.html Running the unit tests ---------------------- $ jasmine-node enums.spec.js Details: http://www.2ality.com/2011/10/jasmine.html Acknowledgements ---------------- - Main idea by Allen Wirfs-Brock - Suggested improvements by Andrea Gianmarchi
The looping construct was non-intuitive and I only figured it with a little trial and error and reading your code. To loop through all the colors in your color example I was only successful with the following:
var colors;
for( var i in color.symbols() ) {
var colorInstance = color.symbols()[i];
colors += colorInstance.name + ':' + colorInstance.de + '<br/>';
}
Intuitively I thought the looping would be like this:
var colors;
for( var colorInstance in color ) {
colors += colorInstance.name + ':' + colorInstance.de + '<br/>';
}
My knowledge of javascript is not sufficient to determine whether or not it's possible for enums.js to support that looping construct.
Hi guys,
Currently, the 'Enum' name gets defined in the enums module as follows:
Enum = function (obj) {
Since var
is not used in the definition, this 'polutes' the JavaScript global namespace with the Enum name. I assume this wasn't the original intent, rather something like:
var Enum = function (obj) {
Or... even simpler:
function Enum(obj) {
Would it be possible to release this under an open-source license?
When i use the following object to instanciate an enum it works:
new enums.Enum({DEFAULT: {name: 'default'}});
But it will fail with the following:
new enums.Enum({DEFAULT: 'default'});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.