Created
April 25, 2011 09:41
-
-
Save fukata/940317 to your computer and use it in GitHub Desktop.
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
> var parent = function(){this.hoge = 'foo';}; | |
> parent.prototype.p = function() { this.px(this.hoge);}; | |
[Function] | |
> parent.prototype.px = function(x) { console.log(x);}; | |
[Function] | |
> var child = function(){parent.apply(this); this.events=['foo'];}; | |
> child.prototype = parent.prototype; | |
{ p: [Function], px: [Function] } | |
> var c = new child(); | |
> c.p(); | |
foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment