Skip to content

Instantly share code, notes, and snippets.

@wolivera
Last active July 12, 2022 14:15
Show Gist options
  • Save wolivera/cd2d6636438cca938e30d290e39ec08d to your computer and use it in GitHub Desktop.
Save wolivera/cd2d6636438cca938e30d290e39ec08d to your computer and use it in GitHub Desktop.
GoF Template
const datastore = {
process: function () {
this.connect();
this.select();
this.disconnect();
return true;
}
};
function inherit(proto) {
const F = function () { };
F.prototype = proto;
return new F();
}
const postgres = inherit(datastore);
// implement template steps
postgres.connect = function () {
console.log("Postgres: connect step");
};
postgres.select = function () {
console.log("Postgres: select step");
};
postgres.disconnect = function () {
console.log("Postgres: disconnect step");
};
postgres.process();
// Postgres: connect step
// Postgres: select step
// Postgres: disconnect step
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment