Skip to content

Instantly share code, notes, and snippets.

@Alcotana
Last active September 30, 2023 03:08
Show Gist options
  • Save Alcotana/e03af38fee5cad764e87df7528cd78dd to your computer and use it in GitHub Desktop.
Save Alcotana/e03af38fee5cad764e87df7528cd78dd to your computer and use it in GitHub Desktop.
Classes-like objects example (you shoud use classes, of course!)
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