Skip to content

Instantly share code, notes, and snippets.

@AccaliaDeElementia
Created July 22, 2015 01:19
Show Gist options
  • Save AccaliaDeElementia/dcfb651a198f60de5ef7 to your computer and use it in GitHub Desktop.
Save AccaliaDeElementia/dcfb651a198f60de5ef7 to your computer and use it in GitHub Desktop.
secure versus unsecure framework, maybe?
'use strict';
function foo() {
setTimeout(function () {
console.log('foo!');
}, this.timeout);
}
function secure() {
value = secured;
return value;
}
function unsecure() {
value = unsecured;
return value;
}
var secured = {
foo: foo.bind({
timeout: 5000
})
},
unsecured = {
foo: foo.bind({
timeout: 0
}),
secure: secure,
unsecure: unsecure
},
value = unsecured;
exports = module.exports = function get() {
return value;
};
'use strict';
var unsecure = require('./a')();
console.log(unsecure);
unsecure.secure();
var secure = require('./a')();
console.log(secure);
secure.foo();
unsecure.foo();
accalia_de_elementia@sockdrawer:~/workspace/test $ node b.js
{ foo: [Function],
secure: [Function: secure],
unsecure: [Function: unsecure] }
{ foo: [Function] }
foo!
foo!
foo! <= There was a five second pause before this printed.
accalia_de_elementia@sockdrawer:~/workspace/test $
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment