Skip to content

Instantly share code, notes, and snippets.

@tksmaru
Created November 11, 2015 21:10
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 tksmaru/f3e0c9e1f7e935f9c738 to your computer and use it in GitHub Desktop.
Save tksmaru/f3e0c9e1f7e935f9c738 to your computer and use it in GitHub Desktop.
javascriptにおける継承の実装サンプル
module.exports = Authentication;
// @Constructor
function Authentication(name) {
this._name = name;
};
Authentication.prototype._login = function(loginId, password) {
throw new Error("not implemented");
};
Authentication.prototype.login = function(loginId, password) {
this._login(loginId, password).then(function(data) {
console.log("login success.");
console.log(data);
}).catch(function(err) {
console.log("login failure");
console.log(err);
});
};
Authentication.prototype.getName = function() {
return this._name;
};
Authentication.prototype.echo = function(text) {
console.log(text);
};
var IceWall = require("./icewall");
debugger;
var inst = new IceWall();
inst.getName();
inst.echo("hi hi");
inst.login("myname", "mypassword");
var Authentication = require("./authentication");
var Util = require("./util");
module.exports = IceWall;
function IceWall() {
Authentication.call(this, "icewall");
};
Util.inherits(IceWall, Authentication);
IceWall.prototype._login = function(loginId, password) {
console.log("login to icewall : " + loginId);
return Promise.resolve(loginId);
};
exports.inherits = function(childConstructor, parentConstructor) {
Object.setPrototypeOf(childConstructor.prototype, parentConstructor.prototype);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment