Message from JavaScript discussions

August 2017

— How I type check the RegExp which confirms it is an object:

/**
* isContainer - Returns `true` if `input` is an Object or Array, otherwise returns `false`.
* param {any} input
* returns {Boolean}
*/
function isContainer(input) {
return (input !== null && (isObject(input) || Array.isArray(input)));
}

Message permanent page

— 

function isObject(input) {
return (input !== null && typeof (input) === "object" && !Array.isArray(input));
}

— Yes I know those two little functions check the same thing twice, they are on the todo list

— I can see cross sections of traversal state and see this right before I get errors about type, as some other functions require objects and throw TypeErrors.

Message permanent page

— The upper props are from the previous iteration and get changed later execution, so ignore those

— But the bottom tuple prop shows the result of traversal

— It chokes on some polymorphic length checking function that fails to ID the tuple elements as objects

Message permanent page

— 

function getContainerLength(input) {
if (Array.isArray(input)) {
return input.length;
}
if (input !== null && typeof input === "object") {
return Object.keys(input).length;
}
throw new TypeError("The given parameter must be an Object or Array");
}

Message permanent page

— The same check the other functions ran... but those did type the input as an object

— I know, but I don't use var anymore

— Because I only use the good parts of JS :)

— I redefined them