Skip to content

[style] game.LOG is why we have ES6 rest parameters #4

@pwfisher

Description

@pwfisher

Please use ES6 for game.LOG: pwfisher@1a24cda

    game.LOG = (level, ...rest) => level < _log_level && console.log(...rest);

This is painful:

game.LOG = function ( a,b,c,d,e,f,g,h,i ) {

      game.LOG = function ( a,b,c,d,e,f,g,h,i ) {
        if (a > _log_level ) return ;

        var log = console.log;
        if (i !== undefined) { log (b,c,d,e,f,g,h,i); return ;}
        if (h !== undefined) { log (b,c,d,e,f,g,h); return ;}
        if (g !== undefined) { log (b,c,d,e,f,g); return ;}
        if (f !== undefined) { log (b,c,d,e,f); return ;}
        if (e !== undefined) { log (b,c,d,e); return ;}
        if (d !== undefined) { log (b,c,d); return ;}
        if (c !== undefined) { log (b, c ); return ;}
        
        log( b );
      };

Why not use ES6? It's 2020. ES6 is vanilla javascript. No need to restrict yourself an archaic style.

Sticking with ES5 only gets you IE11 support and you can get that with webpack if you need it for some reason, and still author ES6 for more readable (better) code.

If you want to be readable:

      // level = priority rank (0 = error, 1 = alert, 2 = warning, 3 = info, 4 = debug)
      // _log_level = verbosity setting
      game.LOG = function (level, ...rest) {
        if (level < _log_level) console.log(...rest);
      };

ES6 and formatting

Automate code formatting. Use Prettier with VSCode: pwfisher@e3a515b

Multiline interpolated string wanted:

html = '<div><div class="inl-bl"><span onanimationend="GAME.ACTIONS.nextLine(this,' + line_delay + ')" class="' + clss + extra_class + '">' + target_txt + '</span></div></div>';

Key/property shorthand wanted:

var ASM_stdlib = { Math: Math, Float64Array: Float64Array, Uint8Array: Uint8Array, Uint32Array: Uint32Array };

const ASM_stdlib = { Math, Float64Array, Uint8Array, Uint32Array };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions