arrow function in class
class Book {
instanceProperty = 'bork';
boundFunction = () => {
return this.instanceProperty;
};
static staticProperty = 'babeliscool';
static staticFn = function() {
return Bork.staticProperty;
};
}class Animal {
constructor(sound = '??') {
this.sound = sound;
}
setNickname(nickname) {
this.nickname = nickname;
}
arrowNotHerited = () => {
console.log('in Animal');
};
}
class Dog extends Animal {
constructor() {
super('wal wal');
this.species = 'mixed';
}
setNickName(nickname) {
this.nickname = 'doggy_' + nickname;
console.log('overriding fn called');
}
arrowNotHerited() {
console.log('in Dog');
}
}
const baduk = new Dog('urururur');
baduk.setNickname('baduk'); // overriding fn called
baduk.arrowNotHerited(); // in dogLast updated
Was this helpful?