Es ist der Code-Snippet in den Async library:Was ist der Zweck von `root = ...` Code in Async-Bibliothek?
if (typeof window == 'object' && this === window) {
root = window;
}
else if (typeof global == 'object' && this === global) {
root = global;
}
else {
root = this;
}
Gibt es einen Grund für all diesen Codes? Warum hat der Autor nicht einfach root = this
verwendet? Die erste Bedingung ist nur gültig, wenn this === window
, also root = window
und root = this
gleichwertig sein sollten. Gleiches gilt für die zweite Bedingung, wobei root = global
root = this
entspricht.
Fehle ich hier etwas?
[ich den Autor gefragt] (https://twitter.com/DenysSeguret/status/606427206806568960). Er wird wahrscheinlich eine bessere Antwort als meine geben;) –