Skip to content

Instantly share code, notes, and snippets.

@jessebeach
Created December 29, 2011 15:19
Show Gist options
  • Save jessebeach/1534531 to your computer and use it in GitHub Desktop.
Save jessebeach/1534531 to your computer and use it in GitHub Desktop.
function scope
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Untitled</title>
<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<link type="text/plain" rel="author" href="/humans.txt" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js"></script>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style type="text/css">
</style>
</head>
<body>
<script>
var message = 'I am global';
function iCanHazGlobalScope (a) {
$('<h1>', {
text: a
})
.css({color: 'blue'})
.appendTo($('body'));
}
(function ($) {
var message = 'I am scoped';
function iCanHazGlobalScope (a) {
$('<h2>', {
text: a
})
.css({color: 'red'})
.appendTo($('body'));
}
iCanHazGlobalScope(message); // output: I am scoped
} (jQuery));
iCanHazGlobalScope(message); // output: I am global
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment