Coder Social home page Coder Social logo

enums's Introduction

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

enums's People

Contributors

rauschma avatar raynos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

enums's Issues

simplify looping construct

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.

Error in Enum constructor when using object

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'});

The 'Enum' name defined / assigned to in enums.js polutes the global namespace

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) {

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.