- All implementations assume
console.logis a static function with side-effect. - All implementations assume
HELLO_WORLDis a constant and does not need to be abstracted and does not need to be passed in as an argument.
const HelloWorld = (<div>{HELLO_WORLD}</div>);
// usage
React.render(HelloWorld, doment.body)// no implementation
// usage
console.log(HELLO_WORLD);Subroutine does not return value.
function printHelloWorld() {
console.log(HELLO_WORLD);
}
// usage
printHelloWorld();This is a technique often used to emulate OOP when OOP is not available such as in languages C and Bash. It is also often used when OOP is not practical, for example when recreating the object is an overhead.
function hellWorld(ctx) {
ctx.log(HELLO_WORLD);
}
// usage
hellWorld(ctx);class HelloWorld {
static print() {
console.log(HELLO_WORLD);
}
}
// usage
HelloWorld.print();class HelloWorld {
print() {
console.log(HELLO_WORLD);
}
}
// usage
new HelloWorld().print()// following code would not work as Console is not publically initializable
class HelloWorld extends Console {
print() {
this.log(HELLO_WORLD);
}
}
// usage
new HelloWorld().log();let myConsole = Object.create(console);
myConsole.print = function () {
this.log(HELLO_WORLD);
};
// usage
myConsole.print();// following code would not work as Console is not publically initializable
function HelloWorld() {
}
HelloWorld.prototype = new Console();
HelloWorld.prototype.print = function () {
this.log(HELLO_WORLD);
};
// usage
new HelloWorld().log();class HelloWorld {
constructor(console) {
this.console = console;
}
print() {
this.console.log(HELLO_WORLD);
}
}
// usage
new HelloWorld(console).print();class HelloWorld {
print(console) {
console.log(HELLO_WORLD);
}
}
// usage
new HelloWorld().print(console);class HelloWorld {
$console;
print(console) {
this.$console.log(HELLO_WORLD);
}
}
// usage
Singleton.get(HelloWorld).print(console);function createHelloWorld(f) {
return {
print() {
f.log(HELLO_WORLD);
}
}
}
// usage
createHelloWorld(console).print();function createHelloWorld() {
return {
print(console) {
console.log(HELLO_WORLD);
}
};
}
// usage
createHelloWorld().print(console);const HelloWorld = (function createHelloWorld() {
return {
print(console) {
console.log(HELLO_WORLD);
}
};
})();
// usage
HelloWorld.print(console);const HelloWorldMixin = {
printHelloWorld() {
console.log(HELLO_WORLD);
}
};
// usage
const obj = Object.assign({}, HelloWorldMixin);
obj.printHelloWorld();const HelloWorldMixin = {
printHelloWorld(console) {
console.log(HELLO_WORLD);
}
};
// usage
const obj = Object.assign({}, HelloWorldMixin);
obj.printHelloWorld(console);const HelloWorldMixin = {
printHelloWorld() {
console.log(HELLO_WORLD);
}
};
// usage
Object.assign(console, HelloWorldMixin);
console.printHelloWorld();console.printHelloWorld = function() {
this.log(HELLO_WORLD);
}
// usage
console.printHelloWorld();// This is a contrived case as IO is all about side-effect
function helloWorld() {
return HELLO_WORLD;
}
// usage
console.log(helloWorld());function helloWorld(console) {
return console.log(HELLO_WORLD);
}
// usage
helloWorld(console);function helloWorld(f) {
return () => f.log(HELLO_WORLD);
}
// usage
helloWorld(console)();function helloWorld() {
return (f) => f.log(HELLO_WORLD);
}
// usage
helloWorld()(console);