Skip to content

Instantly share code, notes, and snippets.

@fukata
Created April 25, 2011 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fukata/940317 to your computer and use it in GitHub Desktop.
Save fukata/940317 to your computer and use it in GitHub Desktop.
JavaScriptによる継承もどき(子と親の繋がりは無)
> 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