News for hackers. Stuff that matters.
Re:Using Dispatch Tables to Avoid Conditionals in JavaScript by arianvanp on Monday May 13, 2013 @11:18AM (#5699129)
I've done this before in scenarios of packet handling. e.g.

    packets.incoming[16] = {
        login_size:     {type: 'byte'},
        magic_code:     {type: 'byte'},
        client_version: {type: 'short'},
        high_detail:    {type: 'byte'},
        archive_crc:    {type: ['int', 9]},
        reported_size:  {type: 'byte'},
        block_opcode:   {type: 'byte'},
        client_key:     {type: ['int', 2]},
        server_key:     {type: ['int', 2]},
        uid:            {type: 'int'},
        username:       {type: 'string'},
        password:       {type: 'string'}
    };

    packets.outgoing[253] = packets.outgoingMessage  = function (message) {
        var length = message.length + 1;
            return {
                opcode:    {type:'byte',          value: 253},
		length:     {type:'byte',           value: length},
		message:	{type:'string',        value: message}
            };
    };

There are no comments on this comment yet.