Created
September 25, 2019 10:53
-
-
Save himstar/9e15e719fd791c36803f7800cbac285f to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/huzopam
This file contains 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
<!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"> | |
var myModule = (function() { | |
'use strict'; | |
var _privateProperty = 'Hello World'; | |
function _privateMethod() { | |
console.log(_privateProperty); | |
} | |
return { | |
publicMethod: function() { | |
_privateMethod(); | |
} | |
}; | |
}()); | |
myModule.publicMethod(); // outputs 'Hello World' | |
console.log(myModule._privateProperty); // is undefined protected by the module closure | |
myModule._privateMethod(); // is TypeError protected by the module closure | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var myModule = (function() { | |
'use strict'; | |
var _privateProperty = 'Hello World'; | |
function _privateMethod() { | |
console.log(_privateProperty); | |
} | |
return { | |
publicMethod: function() { | |
_privateMethod(); | |
} | |
}; | |
}()); | |
myModule.publicMethod(); // outputs 'Hello World' | |
console.log(myModule._privateProperty); // is undefined protected by the module closure | |
myModule._privateMethod(); // is TypeError protected by the module closure</script></body> | |
</html> |
This file contains 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
var myModule = (function() { | |
'use strict'; | |
var _privateProperty = 'Hello World'; | |
function _privateMethod() { | |
console.log(_privateProperty); | |
} | |
return { | |
publicMethod: function() { | |
_privateMethod(); | |
} | |
}; | |
}()); | |
myModule.publicMethod(); // outputs 'Hello World' | |
console.log(myModule._privateProperty); // is undefined protected by the module closure | |
myModule._privateMethod(); // is TypeError protected by the module closure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment