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 that will exist in the global scope
}
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
bark('bob') //notice that call() is only good for one-time use functions- it doesn't permanently bind() anything
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
Insert cell
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
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