Created
February 29, 2012 05:20
-
-
Save efeminella/1938101 to your computer and use it in GitHub Desktop.
One-time function initializations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simply wrap the return value in an immediate function | |
// and return the result. The below example implements // a test for HTML5 WebSocket Feature detection; however, | |
// the same concept applies for any function initializer. | |
var hasWebSockets = ( function (window) { | |
var prefixes = 'ms O Moz Webkit'.split (' ') | |
, n = prefixes.length | |
, i = 0; | |
for (; i < n; ++i) { | |
if ( window [prefixes [i] + 'WebSocket'] ){ | |
return true; | |
} | |
} | |
return 'WebSocket' in window; | |
}( this )); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment