-
-
Save AccaliaDeElementia/dcfb651a198f60de5ef7 to your computer and use it in GitHub Desktop.
secure versus unsecure framework, maybe?
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
'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; | |
}; |
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
'use strict'; | |
var unsecure = require('./a')(); | |
console.log(unsecure); | |
unsecure.secure(); | |
var secure = require('./a')(); | |
console.log(secure); | |
secure.foo(); | |
unsecure.foo(); |
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
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