Skip to content

Instantly share code, notes, and snippets.

@mdmunir
Created May 9, 2015 00:46
Show Gist options
  • Save mdmunir/d68ba5b075ffd899420c to your computer and use it in GitHub Desktop.
Save mdmunir/d68ba5b075ffd899420c to your computer and use it in GitHub Desktop.
Inheritance at javascript
Kelas = function() {
var c = function() {
if (this.initialize) {
this.initialize.apply(this, arguments);
}
}
function Extend(dst, src) {
for (var i in src) {
try {
dst[i] = src[i];
} catch (e) {
}
}
return dst;
}
c.prototype = Object.create(Kelas.prototype);
for (var i = 0; i < arguments.length; i++) {
var a = arguments[i];
if (a.prototype) {
c.prototype = new a();
} else {
Extend(c.prototype, a);
}
}
c.prototype.constructor = c;
Extend(c, c.prototype);
return c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment