Created
June 6, 2017 00:26
-
-
Save ar2zee/d2c0827ec798b928cef3de9204e65fae to your computer and use it in GitHub Desktop.
example of work with 'class' keyword in JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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