我有一个引用事物的函数。为了修复错误,我删除了其他案例陈述(他们不会改变也无法解决问题)。我也删除了return
,因为在这个阶段它也无关紧要。
出于某种原因,我说我在DOM中传递了一个元素:Referencer('id', 'hello')
,尽管Chrome控制台告诉我type = 'id'
if (type === null || "" || "undefined")
每次都会触发。
这是一个JSBin:https://output.jsbin.com/secuciyeko
function Referencer(type, value) {
// Standard Declaration
"use strict";
// Open Console Group
window.console.groupCollapsed("[Scriptbase.js]/[Referencer] @ " + Scriptbase.Time());
// Log Status
window.console.info("[Process Started @ " + Scriptbase.Time() + "]");
/* ------- Computation ------- */
// Local Variables
var a = null;
// Log Status
window.console.log("[Success @ " + Scriptbase.Time() + "]: Checking for unusable values.");
// Value Validation
if (type === null || "" || "undefined") {
// Log Status
window.console.error("[Failure : " + Scriptbase.Time() + "] : Failure to look up '" + type + "' with the value '" + value + "'.");
// Close Console Group
window.console.groupEnd();
// Exit Method
return;
}
if (value === null || "" || "undefined") {
// Log Status
window.console.error("[Failure : " + Scriptbase.Time() + "] : Failure to look up '" + type + "' with the value '" + value + "'.");
// Close Console Group
window.console.groupEnd();
// Exit Method
return;
}
// Log Status
window.console.log("[Success : " + Scriptbase.Time() + "] : Looking up '" + type.toUpperCase() + "' with the value of '" + value + "'.");
// Look Up Value
switch (type) {
case "id":
// Variable Assignment
a = document.getElementById(value);
// Log Status
window.console.log("[Success : " + Scriptbase.Time() + "]: Found an DOM ID of '" + value + "'.");
// Break Case
break;
}
}