Created
June 6, 2014 09:06
-
-
Save ww24/f030530df47990ab6bb3 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
function F(message) { | |
this.message = message; | |
} | |
F.prototype.print = function () { | |
console.log(this.message); | |
}; | |
// F を継承した G | |
function G(message, name) { | |
F.call(this, message); | |
this.name = name; | |
} | |
G.prototype.echo = function () { | |
console.log(this.message + ", " + this.name); | |
}; | |
var f = new F("Hello"); | |
f.print(); | |
var g = new G("Hello", "World"); | |
g.echo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment