Skip to content

Instantly share code, notes, and snippets.

@ar2zee
Created June 6, 2017 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ar2zee/d2c0827ec798b928cef3de9204e65fae to your computer and use it in GitHub Desktop.
Save ar2zee/d2c0827ec798b928cef3de9204e65fae to your computer and use it in GitHub Desktop.
example of work with 'class' keyword in JS
class Mammal {
constructor(sound) {
this._sound = sound;
}
talk() {
return this._sound;
}
}
class Dog extends Mammal {
constructor() { /*super will bound to constructor in Mammal */
super('Woofelifffffffffeeee')
}
}
let Artur = new Mammal('Super-WOof');
let poof = Artur.talk()
console.log(poof);
let Dogie = new Dog();
let shmoof = Dogie.talk()
console.log(shmoof);
Dogie._sound = 'meow';
let newShmoof = Dog.prototype.talk.bind({
_sound: 'Opppa'
})()
console.log(newShmoof);
let prototypeCheck = Dog.prototype.isPrototypeOf(Dogie); // true
let prototypeCheck2 = Dog.prototype.isPrototypeOf(Artur); // false
console.log(prototypeCheck);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment