Created
May 9, 2015 00:46
-
-
Save mdmunir/d68ba5b075ffd899420c to your computer and use it in GitHub Desktop.
Inheritance at javascript
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
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