Message from JavaScript discussions

August 2017

— I feed a RegExp instance into my diff function, and it gets type checked as a traversable object, but then when it gets added to the tuple it somehow isn't an object any more

Message permanent page

— 

Since I rely on a type check prior to adding an object to the traversal stack, there is none at the top of it and it chokes

— How I traverse:

// Node has not been seen before, so traverse it
var nextTuple = {};
// Travese the Tuple's properties
for (var unit in state.tuple) {
if (unit === "search" || unit === "subject" || state.accessor in state.tuple[unit]) {
nextTuple[unit] = state.tuple[unit][state.accessor];
}
}

Message permanent page

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

Message permanent page

— 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