I saw the following JavaScript code, and it confused me, since logically 0 will never be 4 or 5:
if (0 === 4) {
safari.self.addEventListener("message", safariMessageListener, false);
} else if (0 === 5) {
opera.extension.onmessage = operaMessageListener;
}
I will assume that this code works. So the programmer managed somehow to redefine 0 or 0 somehow not to refer to the number 0? Can someone explain this code and why will anyone write such code? What are the advantages of this technique? (except for the confusion of people like me!)
For completeness, this snippet was obtained from the YouTube Center Lubrication Center plug-in. Whose URL is:
https://github.com/YePpHa/YouTubeCenter/wiki/Developer-Version
And the full method:
function initListeners() {
if (support.CustomEvent) {
window.addEventListener("ytc-content-call", eventListener, false);
} else {
window.addEventListener("message", messageListener, false);
}
window.addEventListener("unload", windowUnload, false);
if (0 === 4) {
safari.self.addEventListener("message", safariMessageListener, false);
} else if (0 === 5) {
opera.extension.onmessage = operaMessageListener;
}
}
source
share