Skip to content

Instantly share code, notes, and snippets.

@thecodeite
Created June 23, 2016 08:47
Show Gist options
  • Save thecodeite/373a8a77d150cd41544417517acffab9 to your computer and use it in GitHub Desktop.
Save thecodeite/373a8a77d150cd41544417517acffab9 to your computer and use it in GitHub Desktop.
getUserDetails(cookie, function(error, user) {
if(error) {/* do something with error */}
if(user.isADangerToThePublic) {
console.log('error')
return
}
getUsersName(user, function(error, name, dob) {
if(error) {/* do something with error */}
isItTheirBirthday(dob, function(isBirthday) {
)}
do
})
})
function getUserDetails (cookie) {
console.log('getUserDetails:', this)
const helper = () => {
console.log('this in helper:', this)
}
helper()
}
var myFunction = getUserDetails.bind('cheese')
myFunction()
function doStuff () {
console.log('start')
getUserDetails(cookie)
.then((user) => {
console.log(user)
var sam
if(user.isADangerToThePublic) {
throw new Error('User is bad')
}
return getUsersName(user)
})
.then((name, dob) => {
console.log(name, dob)
return isItTheirBirthday(dob)
})
.then(function (isBirthday) {
console.log('all done. Is it your birthday?' + isBirthday)
})
.catch(function(error) {
console.error('It has all gone wrong!', error)
})
console.log('end')
}
function getUserDetails(cookie, callback) {
setTimeout(function () {
// do some stuff with user
var user = getUser(cookie)
callback(user)
}, 1000)
}
descibe('stuff', function () {
it('should get user from server', function (done) {
//arrange
var cookie = 123
//act
var user = getUserDetails(cookie, function (user) {
// assert
expect(user.name).to.be('sam')
done()
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment