Created
June 24, 2017 13:39
-
-
Save stefanaerts/41f8a9212130143701ade1dc008adbdf to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/cosukavopi
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> | |
<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> |
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
// 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