• Aha! null is an object that isn't an Object!

    From Michael J. Ryan@1:103/705 to GitLab note in main/sbbs on Wednesday, January 27, 2021 15:37:24
    https://gitlab.synchro.net/main/sbbs/-/commit/87dceb286ef8215ca6d2efa122e21d33f505b92b#note_1409

    ```if (obj) {```should be enough of a check here... since, apparently it's Object.keys(obj) that's being used of interest and that should work on anything that isn't null/undefined.
    --- SBBSecho 3.12-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Michael J. Ryan@1:103/705 to GitLab note in main/sbbs on Wednesday, January 27, 2021 15:38:32
    https://gitlab.synchro.net/main/sbbs/-/commit/87dceb286ef8215ca6d2efa122e21d33f505b92b#note_1410

    Or as a short `if (!obj) return null` though haven't looked at the rest of this function in particular, I just tend to prefer to exit early as a pattern.
    --- SBBSecho 3.12-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Deuce@1:103/705 to GitLab note in main/sbbs on Wednesday, January 27, 2021 17:39:49
    https://gitlab.synchro.net/main/sbbs/-/commit/87dceb286ef8215ca6d2efa122e21d33f505b92b#note_1411

    Many truthy things can be non-objects, so testing for thruthiness isn't useful. The test is there specifically to find things that can be passed to Object.keys() without an exception.The else case is an implied return... expanding to something like:```if (typeof obj !== 'object') returnif (obj === null) return```would be needlessly verbose.I generally prefer a single return as a pattern except in cases where indentation gets too deep or when goto would be required. Hunting for returns when debugging is a PITA.
    --- SBBSecho 3.12-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Michael J. Ryan@1:103/705 to GitLab note in main/sbbs on Thursday, February 04, 2021 05:07:11
    https://gitlab.synchro.net/main/sbbs/-/commit/87dceb286ef8215ca6d2efa122e21d33f505b92b#note_1458

    @Deuce Anything that is truthy (and some that aren't, like `false`) can be passed to Object.keys() .. so that's the only check that is needed.```> Object.keys(true)[]> Object.keys(1)[]> Object.keys(new Date())[]> Object.keys(false)[]> Object.keys([])[]``` For that matter, you could just omit the check, and use `Object.keys(Object(obj))` which will work for anything, including `null`.
    --- SBBSecho 3.12-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)