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'; | |
const safeAddExclamation = str => { | |
return `${str}!`; | |
}; | |
module.exports = safeAddExclamation; |
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'; | |
// let's import our safeAddExclamation string function | |
const addExclamation = require('./addExclamation'); | |
console.log(addExclamation("hello")); // logs 'hello!' |
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'; | |
const fs = require('fs'); | |
const https = require('https'); | |
fs.readFile('~/.bitcoind/mywallet.privkey'), function read(err, data) { | |
if (err) { | |
throw err; | |
} |
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
// hmm, why does this need access to the file system and the network? | |
const addHeader = require('./addHeader', {fs, https}); | |
// no authority is being passed here, this is probably safe | |
const addFooter = require('./addFooter'); |
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
// run from command line | |
// saves todo to file, appending it | |
// also displays data, highlighing high, medium, and low priority tasks | |
// Examples: | |
// node todo.js --add --todo="brush teeth" | |
// node todo.js --display | |
const fs = require('fs'); |
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
/* make listener infrastructure */ | |
function makeStateHolder() { | |
let state = undefined; | |
const listeners = []; | |
return { | |
addListener(newListener) { | |
listeners.push(newListener); | |
}, |
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
function makeBankAccount(balance) { | |
stateHolder.updateState(balance); | |
return { | |
withdraw(amount) { | |
balance -= amount; | |
stateHolder.updateState(balance); | |
}, | |
deposit(amount) { | |
balance += amount; | |
stateHolder.updateState(balance); |
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
function makeStateHolder() { | |
let state = undefined; | |
const listeners = []; | |
return { | |
addListener(newListener) { | |
listeners.push(newListener); | |
}, | |
getState() { | |
return state; |
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
const financeListener = { | |
stateChanged(state) { | |
if (state < 4000) { | |
bankAccount.deposit(1000); | |
} | |
}, | |
}; |
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
const webpageListener = { | |
stateChanged(state) { | |
console.log('DISPLAYED BALANCE', state); | |
}, | |
}; |
OlderNewer