Last active
September 30, 2023 03:08
-
-
Save Alcotana/e03af38fee5cad764e87df7528cd78dd to your computer and use it in GitHub Desktop.
Classes-like objects example (you shoud use classes, of course!)
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
var Foo = { | |
construct(who){ | |
this.me = who; | |
this.species = 'fufel'; | |
return this; | |
}, | |
identify(){ | |
return 'I am ' + this.me; | |
} | |
} | |
// class extends Foo | |
var Bar = Object.assign( Object.create(Foo), { | |
construct(who){ | |
// super(..) | |
Foo.construct.call(this, who); | |
this.subtype = 'barashek'; | |
return this; | |
}, | |
speak(){ | |
console.log('Hello, ' + this.identify()); | |
} | |
}); | |
a1 = Object.create(Foo).construct('a1'); | |
b1 = Object.create(Bar).construct('b1'); | |
console.log(a1); | |
console.log(b1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment