Skip to content

Instantly share code, notes, and snippets.

@efeminella
Created February 29, 2012 05:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save efeminella/1938101 to your computer and use it in GitHub Desktop.
Save efeminella/1938101 to your computer and use it in GitHub Desktop.
One-time function initializations
// 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