Message from JavaScript discussions

December 2016

— You are crack

— 

// Traverse through a tree of Objects and Arrays.
// Executes a callback for each Property or Index.
// |!| Warning: Circular references may cause an infinite loop.
traverse: function (obj, callback) {
var uid = guid();
if (FluxAxe.isObject(obj)) {
if (Object.keys(obj).length > 0) {
for (var prop in obj) {
console.log("Running Object - Prop: " + prop);
callback(prop);
}
}
} else if (Array.isArray(obj)) {
if (obj.length > 0) {
var count = obj.length > 0 ? obj.length - 1 : 0;
for (var i = 0; i <= count; i++) {

console.log("Running Array - Index: " + i + " of " + count);
callback(i);
}
}
}

— 

// Create a deep clone of an Object or Array
clone: function (obj) {
if (FluxAxe.isPrimitive(obj)) {
// Clone a Primitive.
console.log("Cloning Primitive: " + obj);
return FluxAxe.newPrimitive(obj);
} else if (FluxAxe.isContainer(obj)) {
// Clone an Object or Array.
var objClone = Array.isArray(obj) ? new Array() : new Object();
console.log("Cloning Object/Array: ");
console.log(obj);
// Traverse the Container and clone it's contents.
FluxAxe.traverse(obj, function (loc) {
console.log("Traversal callback executing!");
objClone[loc] = FluxAxe.clone(obj[loc]);
console.log("Cloned item result: ");
console.log(objClone);
});
return objClone;
}
},

Message permanent page

— World's smallest deep clone

— No functions, null, or symbols though

— So not better than using JSON.parse and JSON.stringify, yet

— Hey guys, I'm confused with js and still learned it

— Why I run js in console browser

— Lol

— What are you confused about?

— I am still learning myself but maybe I could help somehow

— Man, writing documentation is hard