Last active
July 12, 2022 14:15
-
-
Save wolivera/cd2d6636438cca938e30d290e39ec08d to your computer and use it in GitHub Desktop.
GoF Template
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
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