Message from JavaScript discussions

September 2020

— Drop in, let's be "friends"🤤

— 

Hi,
I am trying to understand some code fragment.
There is one line I can not see why/when/how it would be helpful
The output is always the same, even if I remove it.
Only change , when looking at family it is either the code or "[native code]"

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

Person.prototype.hasAge = function () {
return this.age;
};
var family ={};
family.myFather = new Person( 50);
family.myMother = new Person( 40);

console.log (family.myFather.hasAge());
console.log (family.myMother.hasAge());

https://jsfiddle.net/mysticJay/0jkq2xyr/

— Kek, why you bind() that

— You already call it over correct object, so if you completely remove this.hasAge assignment and it will be ok

Message permanent page

— You don't need bindings for this use-case

— Bindings are useful with the event handlers, to set the state of that object. take as a rule to not to bind if it's not event/callback

Message permanent page

— Use proper classes, if you want OOP :)

— 

class Person() {
constructor(age) {
this.age = age
}
hasAge() {
return this.age
}
}
const father = new Person(50)

father.hasAge() // 50

Message permanent page

— No bind, no prototype..

— Proper classes aren't as good as constructor pattern imo🤤

— Why did this make me laugh so hard

— Bruh do you even typescript