Skip to content

Instantly share code, notes, and snippets.

class MI{
#secretcode=123;
getAccess(value){
if(value===this.#secretcode)return 'granted access.';
else return 'access denied.'
}
}
class Home{
sleep(){ console.log(`${this.name} is sleeping.`) }
resting(){console.log(`${this.name} is resting`)}
static atHome(){console.log('I am at Home.')}
}
class Life{
constructor(medium){
this.medium=medium;
}
eat(){return `get food from ${this.medium}`};
}
class Human extends Life{
constructor(identity,medium){
function Life(medium){
this.medium=medium;
}
Life.prototype.eat=function(){return `get food from ${this.medium}`};
function Human(identity,medium){
Object.setPrototypeOf(Human,Life);
Life.call(this,medium);
this.identity=identity;
const one={
who(){return 'I am the one'}
}
const two={
getRoots(){
return super.who();
}
class Person{
constructor(name){
this.name=name;
};
run(){ return `${this.name} is running.`};
sleep(){return `${this.name} is sleeping.`};
/** Constructor Functions **/
function Person(name){
this.name=name;
}
Person.isNamed=function(instance){return !!instance.name}
var you=new Person(); /** @returns
Person { name: undefined
__proto__: constructor: ƒ Person{
isNamed: ƒ (instance)
const Person=function(name){
this.name=name;
}
Person.prototype.run=function (){ return `${this.name} is running.`};
Person.prototype.sleep=function (){return `${this.name} is sleeping.`};
let woman=new Person('She');
let man=new Person('He');
const person={
run(){ return `${this.name} is running.`},
sleep(){return `${this.name} is sleeping.`}
}
let woman=Object.assign( Object.create(person) , {name:'She'} ); /* @returns {
name: "She"
(function(){}).prototype
@returns {
constructor: ƒ () //function on which prototype property was accessed.
__proto__: Object
}