Skip to content

Instantly share code, notes, and snippets.

@mi-skam
Created December 2, 2020 10:55
Show Gist options
  • Save mi-skam/bc9acb51c4fa8c152bbccbb426ea4519 to your computer and use it in GitHub Desktop.
Save mi-skam/bc9acb51c4fa8c152bbccbb426ea4519 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/wotipih
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
const revealingModule = (function() {
const privateVar = "Ben Cherry",
publicVar = "Hey there!";
function privateFunction() {
console.log( "Name:" + privateVar );
}
function publicSetName( strName ) {
privateVar = strName;
}
function publicGetName() {
privateFunction();
}
return {
setName: publicSetName,
greeting: publicVar,
getName: publicGetName
};
})()
console.log(revealingModule.getName())
</script>
<script id="jsbin-source-javascript" type="text/javascript">const revealingModule = (function() {
const privateVar = "Ben Cherry",
publicVar = "Hey there!";
function privateFunction() {
console.log( "Name:" + privateVar );
}
function publicSetName( strName ) {
privateVar = strName;
}
function publicGetName() {
privateFunction();
}
return {
setName: publicSetName,
greeting: publicVar,
getName: publicGetName
};
})()
console.log(revealingModule.getName())</script></body>
</html>
const revealingModule = (function() {
const privateVar = "Ben Cherry",
publicVar = "Hey there!";
function privateFunction() {
console.log( "Name:" + privateVar );
}
function publicSetName( strName ) {
privateVar = strName;
}
function publicGetName() {
privateFunction();
}
return {
setName: publicSetName,
greeting: publicVar,
getName: publicGetName
};
})()
console.log(revealingModule.getName())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment