Last active
June 17, 2016 22:21
-
-
Save tompazourek/92ed322586fd95b5a41ad43e3073c7c3 to your computer and use it in GitHub Desktop.
JS inheritance
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
var Bar = (function(parent) { | |
// constructor | |
var cls = function Bar(/* ... */) { | |
parent.call(this, /* ... */); | |
/* ... */ | |
}; | |
// inheritance | |
inherits(cls, parent); | |
// methods | |
cls.prototype.baz = function() { | |
/* ... */ | |
); | |
return cls; | |
})(Foo); | |
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
var inherits = function(child, parent) { | |
child.prototype = Object.create(parent.prototype); | |
child.prototype.constructor = child; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment