Skip to content

Instantly share code, notes, and snippets.

@the-liquid-metal
Created January 11, 2021 00:21
Show Gist options
  • Save the-liquid-metal/5c03256c332a20dd881498c4f2a41db0 to your computer and use it in GitHub Desktop.
Save the-liquid-metal/5c03256c332a20dd881498c4f2a41db0 to your computer and use it in GitHub Desktop.
*PHP*
================
class a {
function f1() {echo "f1 from 'a'";}
}
class b extend a {
function b1() {echo "b1 from 'b'";}
function b2() {echo "b1 from 'b'";}
}
class c extend b {
function c1() {echo "c1 from 'c'";}
function c2() {echo "c1 from 'c'";}
}
class d extend c {
function d1() {echo "d1 from 'd'";}
function d2() {echo "d1 from 'd'";}
}
class e extend d {
function f1() {echo "d1 from 'd'";}
function call1() {$this->f1();}
// enggak ada ada ekivalennya dg JAVASCRIPT ES5,
// alias sama aja dg manggil: $this->f1()
function call2() {echo '---'}
function call3() {parent::f1();}
}
$v1 = new e;
$v1->call1();
$v1->call2();
$v1->call3();
*JAVASCRIPT ES5*
================
a = function(){};
a.prototype.f1 = function(){console.log("f1 from 'a'")}
a.prototype.f2 = function(){console.log("f2 from 'a'")}
// =====
b = function(){};
b.prototype = Object.create(a.prototype);
b.prototype.b1 = function(){console.log("b1 from 'b'")}
b.prototype.b2 = function(){console.log("b2 from 'b'")}
// =====
c = function(){};
c.prototype = Object.create(b.prototype);
c.prototype.c1 = function(){console.log("c1 from 'c'")}
c.prototype.c2 = function(){console.log("c2 from 'c'")}
// =====
d = function(){};
d.prototype = Object.create(c.prototype);
d.prototype.d1 = function(){console.log("d1 from 'd'")}
d.prototype.d2 = function(){console.log("d2 from 'd'")}
// =====
e = function(){};
e.prototype = Object.create(d.prototype);
e.prototype.f1 = function(){console.log("f1 from 'e'")}
e.prototype.call1 = function(){this.f1()}
e.prototype.call2 = function(){this.__proto__.f1()}
e.prototype.call3 = function(){this.__proto__.__proto__.f1()}
v1 = new e();
v1.call1();
v1.call2();
v1.call3();
*JAVASCRIPT ES6*
================
class a {
f1(){console.log("f1 from 'a'")}
}
class b extends a {
b1(){console.log("b1 from 'b'")}
b2(){console.log("b2 from 'b'")}
}
class c extends b {
c1(){console.log("c1 from 'b'")}
c2(){console.log("c2 from 'b'")}
}
class d extends c {
d1(){console.log("d1 from 'b'")}
d2(){console.log("d2 from 'b'")}
}
class e extends d {
f1(){console.log("f1 from 'e'")}
call1(){this.f1()}
// enggak ada ada ekivalennya dg JAVASCRIPT ES5,
// alias sama aja dg manggil: this.f1()
call2(){console.log("---")}
call3(){super.f1()}
}
v1 = new e();
v1.call1();
v1.call2();
v1.call3();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment