Message from JavaScript discussions

September 2020

β€” "callback" might be the keyword.
the code I am looking into is part of a large project, and there are "callback functions".
in fact gapi is used to access G-drive.

the tips on how to change are generally welcome, but first i need to understand what this part of the code is doing and why certain syntax was used.

we have already seen, that dropping the "bind" line has an effect (native code).

so what is this on "callback" you mentioned. can you elaborate?

Message permanent page

β€” 

(native code) means (don't put your nose) orπŸ˜… i can't see what you see, binding means additional (native) code will be generated, right.. operations aren't free😫

β€” Callback is mouse.onclick = callback where callback = handler.bind(scope) is bound, might be => in the constructor function..

function Person(age) {
this.age = age;
this.hasAge = () => this.age
//this.hasAge = () => age
}

Message permanent page

β€” I think better would be getAge instead of hasAge.. otherwise I would expect boolean value

β€” Exactly

β€” Or if you like functional style:

const person = age => ({ age })
const getAge = person => person.age
const father = person(50)
const fatherAge = getAge(father)

Message permanent page

β€” Const const const const 🀀

β€” Yes.. a good brick wall is better than a v-shaped mess

β€” If you have now an array of persons.. how do you retrieve their age?
in OOP style:

persons.map(person => person.getAge())


in FP Style:
persons.map(getAge)

Message permanent page

β€” ScatteredπŸ˜‘

β€” Expressive, I would say 🧐

β€” Could it be that the code generates a situation, where age is the same for each person? so where ever I change age it will be the identical value, while

myFather.name= "John"; myMother.name="Jane";

stay disjunct properties?

Message permanent page