Skip to content

Instantly share code, notes, and snippets.

@bmavity
Created February 16, 2011 20:15
Show Gist options
  • Save bmavity/830089 to your computer and use it in GitHub Desktop.
Save bmavity/830089 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Sample Page for Module Intro</title>
</head>
<body>
<h1>Variables added to window object</h1>
<script src="samplePageExternal.js"></script>
<script>
// For IE. You've brought the alert punishment on yourself. ;)
if(!window.console) {
window.console = alert;
}
// This is defined in the external JavaScript file
// outside of a function, and with the var keyword.
console.log(window.outsideFunctionWithVar); // 2
// This is defined in the external JavaScript file
// inside of a function, but without the var keyword.
console.log(window.insideFunctionWithoutVar); // 'hippo'
// This is defined in the external JavaScript file
// inside a function, and with the var keyword.
console.log(window.insideFunctionWithVar); // undefined
var thisPage = 'on it';
// Defined above
console.log(window.thisPage); // 'on it'
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment