Published
Edited
Sep 25, 2019
8 forks
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
doggo = {
return {
bark: function(person) {
return this.sound + ', says ' + person
},
sound: "wooooof"
}
}
Insert cell
justBark = doggo.bark
Insert cell
justBark('bob') //'this' is undefined because justBark is outside of the doggo object scope
Insert cell
Insert cell
boundBark = {
var boundBark = doggo.bark
return boundBark.bind(doggo) //note that this is actually a new function
}
Insert cell
boundBark('bob')
Insert cell
Insert cell
Insert cell
bark = doggo.bark
Insert cell
bark.bind(doggo)('bob')===bark.call(doggo, 'bob')
Insert cell
Insert cell
Insert cell
bark.call(doggo, 'bob')===bark.apply(doggo, ['bob'])
Insert cell
Insert cell
Object.getPrototypeOf(function() {})
Insert cell
Object.getPrototypeOf(Object.getPrototypeOf(function() {}))
Insert cell
Insert cell
{
function func() {}
func.attr = 'Im an attribute!'
return func.attr
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
bankApplication = (function() {
var checkPassword = utilityFunctions.checkPassword
var resetPassword = utilityFunctions.resetPassword
//your code here
return {
//your code here
}
})()
Insert cell
{
if(Object.keys(bankApplication).length===0)
return "Your function will be unit tested here"
try
{
expect(bankApplication.checkPassword(`Shh, I'm secret`)).to.equal(true)
expect(bankApplication.resetPassword(`Shh, I'm secret`,`bob`)).to.equal("Password reset successfully.")
expect(bankApplication.checkPassword(`Shh, I'm secret`)).to.equal(false)
expect(bankApplication.checkPassword(`bob`)).to.equal(true)
bankApplication.setBalance(`bob`, 1000)
expect(bankApplication.getBalance(`bob`)).to.equal(1000)
bankApplication.resetPassword(`bob`, `Shh, I'm secret`)
return success()
}
catch(err)
{
return failure()
}
}
Insert cell
Insert cell
// please do not convert bind(), apply(), or call() into a
// different function (ex don't use call() where apply() is written)
returnObject = (function() {
var cpass = utilityFunctions.checkpassword
var reset = utilityFunctions.resetpassword
var secret = utilityFunctions.getSecret
var userObj;
var pass = 'Shh, I'm secret'
var checkPassword = cpass.bind(utilityFunctions)
var AuthUser = checkPassword(pass)
if(AuthUser) {
userObj = {
password: pass,
canResetPass: reset.call([pass,'bob'],utilfxns),
theSeeeecret: secret.apply(utilfunction, 'bob')
}
utilityFunctions.resetPassword('bob', pass)
}
else {
userObj = {
theSeeeecret: '*blows raspberry* You can\'t get me, na-na-na-na-na,nah'
}
}
return(userObj)
})()
Insert cell
{
try
{
expect(returnObject.password).to.equal(`Shh, I'm secret`)
expect(returnObject.canResetPass).to.equal("Password reset successfully.")
expect(returnObject.theSeeeecret).to.equal('I is sooooo secret')
return success()
}
catch(err)
{
return failure()
}
}
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more