Skip to content

Instantly share code, notes, and snippets.

Created January 4, 2017 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/ca9cee41c804b642bcf026566e51d0ad to your computer and use it in GitHub Desktop.
Save anonymous/ca9cee41c804b642bcf026566e51d0ad to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/yufagusugu
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.rawgit.com/zloirock/core-js/master/client/shim.min.js"></script>
<script src="https://wzrd.in/standalone/tape@latest"></script>
<script src="https://wzrd.in/standalone/tap-browser-color@latest"></script>
<script src="http://fb.me/react-with-addons-0.14.3.js"></script>
<script src="http://fb.me/react-dom-0.14.3.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script>
window.test = tape;
tapBrowserColor();
</script>
<script id="jsbin-javascript">
// https://gist.github.com/ericelliott/2b624243f030405abe0c
const getSecret = (secret) => {
return {
get: () => secret
};
};
test('Closure for object privacy.', assert => {
const msg = '.get() should have access to the closure.';
const expected = 1;
const obj = getSecret(1);
const actual = obj.get();
try {
assert.ok(secret, 'This throws an error.');
} catch (e) {
assert.ok(true, `The secret var is only available
to privileged methods.`);
}
assert.equal(actual, expected, msg);
assert.end();
});
</script>
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html>
<html>
<head>
<script src="https://cdn.rawgit.com/zloirock/core-js/master/client/shim.min.js"><\/script>
<script src="https://wzrd.in/standalone/tape@latest"><\/script>
<script src="https://wzrd.in/standalone/tap-browser-color@latest"><\/script>
<script src="//fb.me/react-with-addons-0.14.3.js"><\/script>
<script src="//fb.me/react-dom-0.14.3.js"><\/script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script>
window.test = tape;
tapBrowserColor();
<\/script>
</body>
</html>
</script>
<script id="jsbin-source-javascript" type="text/javascript">// https://gist.github.com/ericelliott/2b624243f030405abe0c
const getSecret = (secret) => {
return {
get: () => secret
};
};
test('Closure for object privacy.', assert => {
const msg = '.get() should have access to the closure.';
const expected = 1;
const obj = getSecret(1);
const actual = obj.get();
try {
assert.ok(secret, 'This throws an error.');
} catch (e) {
assert.ok(true, `The secret var is only available
to privileged methods.`);
}
assert.equal(actual, expected, msg);
assert.end();
});
</script></body>
</html>
// https://gist.github.com/ericelliott/2b624243f030405abe0c
const getSecret = (secret) => {
return {
get: () => secret
};
};
test('Closure for object privacy.', assert => {
const msg = '.get() should have access to the closure.';
const expected = 1;
const obj = getSecret(1);
const actual = obj.get();
try {
assert.ok(secret, 'This throws an error.');
} catch (e) {
assert.ok(true, `The secret var is only available
to privileged methods.`);
}
assert.equal(actual, expected, msg);
assert.end();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment