2011-01-07 126 views

回答

3

這裏的eval是完全沒有意義的:

// since everything in the global scope gets defined on 'window' 
typeof window[r] === 'undefined'; 

這將做確切同樣的事情,也注意到r泄漏到了全球範圍。

// Check requirements Prototype and Scriptaculous 
(function() { 
    var requires = ['Prototype', 'Scriptaculous']; 

    var r = ''; // make sure to __not__ override a global r 
    while (r = requires.pop()) { 
     if (typeof window[r] === 'undefined') { 
      alert(r + ' is required'); 
     } 
    } 
}()); 
+1

謝謝你,謝謝你的擡起頭,對全局變量。 – 2011-01-09 04:07:35

0
while (r = requires.pop()) { 
    if (typeof window[r] == "undefined") alert(r + ' is required'); 
} 
1

如何

if (typeof window[r] == "undefined") 
+0

哈哈...連續3人 – mplungjan 2011-01-07 17:48:46

相關問題