-
-
Save tmbtech/694bdfdc0eede7a6bbcc5c0a9d65df77 to your computer and use it in GitHub Desktop.
Revisions
-
leonyu revised this gist
May 16, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -36,11 +36,11 @@ 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. ```js function helloWorld(ctx) { ctx.log(HELLO_WORLD); } // usage helloWorld(console); ``` ### Static-typed object-oriented ### -
leonyu revised this gist
May 16, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -40,7 +40,7 @@ function hellWorld(ctx) { ctx.log(HELLO_WORLD); } // usage hellWorld(conole); ``` ### Static-typed object-oriented ### -
leonyu revised this gist
May 16, 2016 . 1 changed file with 8 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -103,8 +103,8 @@ HelloWorld.prototype.print = function () { new HelloWorld().log(); ``` ### Injection-based ### #### constructor injection #### ```js class HelloWorld { constructor(console) { @@ -118,7 +118,7 @@ class HelloWorld { new HelloWorld(console).print(); ``` #### Parameter Injection #### ```js class HelloWorld { print(console) { @@ -129,7 +129,7 @@ class HelloWorld { new HelloWorld().print(console); ``` #### Autowired Injection #### ```js class HelloWorld { $console; @@ -140,8 +140,8 @@ class HelloWorld { // usage Singleton.get(HelloWorld).print(console); ``` ### Factory ### #### Constructor Injection #### ```js function createHelloWorld(f) { return { @@ -154,7 +154,7 @@ function createHelloWorld(f) { createHelloWorld(console).print(); ``` #### Parameter Injection #### ```js function createHelloWorld() { return { @@ -167,7 +167,7 @@ function createHelloWorld() { createHelloWorld().print(console); ``` #### IIFE / old-school module pattern #### ```js const HelloWorld = (function createHelloWorld() { return { -
leonyu revised this gist
May 16, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ These examples are presented in an attempt to show how each coding styles attemp Since every coding style can abstract away data into a parameter or variable, there is no point for us to show that. All implementations assume `HELLO_WORLD` is a constant that is always inlined. This way it reduces the variations we need to present. (To make an anology, if we were to implement `incrementByOne`, would we need to inline the number `1` or pass it in as parameter?) CAVEAT/LIMITATION: All implementations also assume `console` is static. In case of OOP inheritance, `Console` is assumed to be extendable. In case of functional programming, `console.log` is asumed to be a function that can be passed around without further modification. ## Declarative ## ```jsx -
leonyu revised this gist
May 16, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ These examples are presented in an attempt to show how each coding styles attemp * Invocation of `console.log` * Declaration of `HELLO_WORLD` Since every coding style can abstract away data into a parameter or variable, there is no point for us to show that. All implementations assume `HELLO_WORLD` is a constant that is always inlined. This way it reduces the variations we need to present. (To make an anology, if we were to implement `incrementByOne`, would we need to inline the number `1` or pass it in as parameter?) All implementations also assume `console` is static. In case of OOP, `Console` is assumed to be extendable. In case of functional programming, `console.log` is asumed to be a function that can be passed around without further modification. -
leonyu revised this gist
May 16, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ These examples are presented in an attempt to show how each coding styles attemp * Invocation of `console.log` * Declaration of `HELLO_WORLD` Since every coding style can abstract away data into a parameter or variable, there is no point for us to show that. All implementations assume `HELLO_WORLD` is a constant that is always inlined. This way it reduces the variations we need to present. (To make an anology, if you were to implement `incrementByOne`, would `1` be inlined or passed in as variable?) All implementations also assume `console` is static. In case of OOP, `Console` is assumed to be extendable. In case of functional programming, `console.log` is asumed to be a function that can be passed around without further modification. -
leonyu revised this gist
May 16, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ These examples are presented in an attempt to show how each coding styles attemp * Invocation of `console.log` * Declaration of `HELLO_WORLD` Since every coding style can abstract away data into a parameter or variable, there is no point for us to show that. All implementations assume `HELLO_WORLD` is a constant that is always inlined. This way it reduces the variations we need to present. All implementations also assume `console` is static. In case of OOP, `Console` is assumed to be extendable. In case of functional programming, `console.log` is asumed to be a function that can be passed around without further modification. -
leonyu revised this gist
May 16, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ These examples are presented in an attempt to show how each coding styles attemp * Invocation of `console.log` * Declaration of `HELLO_WORLD` Since every coding style can abstract away data into a parameter or variable, there is no point for us to show that. All implementations assume `HELLO_WORLD` is a constant that is always inline. This way it reduces the variations we need to present. All implementations also assume `console` is static. In case of OOP, `Console` is assumed to be extendable. In case of functional programming, `console.log` is asumed to be a function that can be passed around without further modification. -
leonyu revised this gist
May 16, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,8 @@ These examples are presented in an attempt to show how each coding styles attempts to or does not attempt to isolate side-effects. There are only 2 semantic elements in a barebone "Hello World" implementation: * Invocation of `console.log` * Declaration of `HELLO_WORLD` * Since every coding style can abstract away data into a parameter or variable, there is no point for us to show that. All implementations assume `HELLO_WORLD` is a constant that is always inline. This way it reduces the variations we need to present. All implementations also assume `console` is static. In case of OOP, `Console` is assumed to be extendable. In case of functional programming, `console.log` is asumed to be a function that can be passed around without further modification. -
leonyu revised this gist
May 16, 2016 . 1 changed file with 6 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,9 @@ These examples are presented in an attempt to show how each coding styles attempts to or does not attempt to isolate side-effects. There are only 2 semantic elements in a barebone "Hello World" implementation: * Invocation of `console.log` * Declaration of `HELLO_WORLD` Since every coding style can abstract away data into a parameter or variable, there is no point for us to show that. All implementations assume `HELLO_WORLD` is a constant that is always inline. This way it reduces the variations we need to present. All implementations also assume `console` is static. In case of OOP, `Console` is assumed to be extendable. In case of functional programming, `console.log` is asumed to be a function that can be passed around without further modification. ## Declarative ## ```jsx -
leonyu revised this gist
May 16, 2016 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ * All implementations assume `HELLO_WORLD` is a constant and does not need to be abstracted and does not need to be passed in as an argument. * All implementations assume `console.log` is a static function. In case of functional programming, it can be passed around (not the case in Chrome). ## Declarative ## ```jsx @@ -226,7 +226,6 @@ console.printHelloWorld(); ### Eager Eval ### #### Side-effect on usage #### ```js function helloWorld() { return HELLO_WORLD; } -
leonyu revised this gist
May 16, 2016 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -17,6 +17,7 @@ React.render(HelloWorld, doment.body) console.log(HELLO_WORLD); ``` #### Subroutine #### Subroutine does not return value. ```js function printHelloWorld() { console.log(HELLO_WORLD); -
leonyu revised this gist
May 16, 2016 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,9 @@ function printHelloWorld() { printHelloWorld(); ``` #### Context-passing #### 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. ```js function hellWorld(ctx) { ctx.log(HELLO_WORLD); -
leonyu revised this gist
May 16, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -12,9 +12,9 @@ React.render(HelloWorld, doment.body) ### Procedural ### #### Direct invocation #### ```js // no implementation // usage console.log(HELLO_WORLD); ``` #### Subroutine #### ```js -
leonyu revised this gist
May 16, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -31,7 +31,7 @@ function hellWorld(ctx) { ctx.log(HELLO_WORLD); } // usage hellWorld(ctx); ``` ### Static-typed object-oriented ### -
leonyu revised this gist
May 16, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ function printHelloWorld() { printHelloWorld(); ``` #### Context-passing / OOP in non-OOP languages #### ```js function hellWorld(ctx) { ctx.log(HELLO_WORLD); -
leonyu revised this gist
May 16, 2016 . 1 changed file with 49 additions and 39 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -25,6 +25,15 @@ function printHelloWorld() { printHelloWorld(); ``` #### Context-passing / Idomatic OOP #### ```js function hellWorld(ctx) { ctx.log(HELLO_WORLD); } // usage printHelloWorld(); ``` ### Static-typed object-oriented ### #### Static #### ##### Static method ##### @@ -49,6 +58,42 @@ class HelloWorld { new HelloWorld().print() ``` ### Inheritance ### #### Classical Inheritance #### ```js // following code would not work as Console is not publically initializable class HelloWorld extends Console { print() { this.log(HELLO_WORLD); } } // usage new HelloWorld().log(); ``` #### Prototypical inheritance #### ```js let myConsole = Object.create(console); myConsole.print = function () { this.log(HELLO_WORLD); }; // usage myConsole.print(); ``` #### Old-school class pattern #### ```js // 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(); ``` #### Injection-based #### ##### constructor injection ##### ```js @@ -86,8 +131,8 @@ class HelloWorld { // usage Singleton.get(HelloWorld).print(console); ``` #### Factory #### ##### Constructor Injection ##### ```js function createHelloWorld(f) { return { @@ -100,7 +145,7 @@ function createHelloWorld(f) { createHelloWorld(console).print(); ``` ##### Parameter Injection ##### ```js function createHelloWorld() { return { @@ -113,7 +158,7 @@ function createHelloWorld() { createHelloWorld().print(console); ``` ##### IIFE / old-school module pattern ##### ```js const HelloWorld = (function createHelloWorld() { return { @@ -126,41 +171,6 @@ const HelloWorld = (function createHelloWorld() { HelloWorld.print(console); ``` ### Dynamic-typed object-oriented ### #### Mixin #### ##### Static invocation ##### -
leonyu revised this gist
May 16, 2016 . 1 changed file with 40 additions and 40 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -86,6 +86,46 @@ class HelloWorld { // usage Singleton.get(HelloWorld).print(console); ``` ### Factory ### #### Constructor Injection #### ```js function createHelloWorld(f) { return { print() { f.log(HELLO_WORLD); } } } // usage createHelloWorld(console).print(); ``` #### Parameter Injection #### ```js function createHelloWorld() { return { print(console) { console.log(HELLO_WORLD); } }; } // usage createHelloWorld().print(console); ``` #### IIFE / old-school module pattern #### ```js const HelloWorld = (function createHelloWorld() { return { print(console) { console.log(HELLO_WORLD); } }; })(); // usage HelloWorld.print(console); ``` ### Inheritance ### #### Classical Inheritance #### ```js @@ -169,46 +209,6 @@ console.printHelloWorld = function() { console.printHelloWorld(); ``` ## Functional programming ## ### Eager Eval ### #### Side-effect on usage #### -
leonyu revised this gist
May 16, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -160,7 +160,7 @@ Object.assign(console, HelloWorldMixin); console.printHelloWorld(); ``` ##### Monkey-pactching with method ##### ```js console.printHelloWorld = function() { this.log(HELLO_WORLD); -
leonyu revised this gist
May 16, 2016 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -147,7 +147,8 @@ const obj = Object.assign({}, HelloWorldMixin); obj.printHelloWorld(console); ``` #### Monkey-pactching #### ##### Monkey-pactching with mixins ##### ```js const HelloWorldMixin = { printHelloWorld() { @@ -159,7 +160,7 @@ Object.assign(console, HelloWorldMixin); console.printHelloWorld(); ``` #### Monkey-pactching with method #### ```js console.printHelloWorld = function() { this.log(HELLO_WORLD); -
leonyu revised this gist
May 16, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -214,7 +214,7 @@ HelloWorld.print(console); ```js // This is a contrived case as IO is all about side-effect function helloWorld() { return HELLO_WORLD; } // usage console.log(helloWorld()); -
leonyu revised this gist
May 16, 2016 . 1 changed file with 23 additions and 23 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ * All implementations assume `console.log` is a static function with side-effect. * All implementations assume `HELLO_WORLD` is a constant and does not need to be abstracted and does not need to be passed in as an argument. ## Declarative ## ```jsx const HelloWorld = (<div>{HELLO_WORLD}</div>); // usage React.render(HelloWorld, doment.body) ``` @@ -12,14 +12,14 @@ React.render(HelloWorld, doment.body) ### Procedural ### #### Direct invocation #### ```js console.log(HELLO_WORLD); // usage // none - procedural code ``` #### Subroutine #### ```js function printHelloWorld() { console.log(HELLO_WORLD); } // usage printHelloWorld(); @@ -31,7 +31,7 @@ printHelloWorld(); ```js class HelloWorld { static print() { console.log(HELLO_WORLD); } } // usage @@ -42,7 +42,7 @@ HelloWorld.print(); ```js class HelloWorld { print() { console.log(HELLO_WORLD); } } // usage @@ -57,7 +57,7 @@ class HelloWorld { this.console = console; } print() { this.console.log(HELLO_WORLD); } } // usage @@ -68,7 +68,7 @@ new HelloWorld(console).print(); ```js class HelloWorld { print(console) { console.log(HELLO_WORLD); } } // usage @@ -80,7 +80,7 @@ new HelloWorld().print(console); class HelloWorld { $console; print(console) { this.$console.log(HELLO_WORLD); } } // usage @@ -92,7 +92,7 @@ Singleton.get(HelloWorld).print(console); // following code would not work as Console is not publically initializable class HelloWorld extends Console { print() { this.log(HELLO_WORLD); } } // usage @@ -103,7 +103,7 @@ new HelloWorld().log(); ```js let myConsole = Object.create(console); myConsole.print = function () { this.log(HELLO_WORLD); }; // usage myConsole.print(); @@ -116,7 +116,7 @@ function HelloWorld() { } HelloWorld.prototype = new Console(); HelloWorld.prototype.print = function () { this.log(HELLO_WORLD); }; // usage new HelloWorld().log(); @@ -127,7 +127,7 @@ new HelloWorld().log(); ```js const HelloWorldMixin = { printHelloWorld() { console.log(HELLO_WORLD); } }; // usage @@ -139,7 +139,7 @@ obj.printHelloWorld(); ```js const HelloWorldMixin = { printHelloWorld(console) { console.log(HELLO_WORLD); } }; // usage @@ -151,7 +151,7 @@ obj.printHelloWorld(console); ```js const HelloWorldMixin = { printHelloWorld() { console.log(HELLO_WORLD); } }; // usage @@ -162,7 +162,7 @@ console.printHelloWorld(); ### Monkey-pactching method ### ```js console.printHelloWorld = function() { this.log(HELLO_WORLD); } // usage console.printHelloWorld(); @@ -174,7 +174,7 @@ console.printHelloWorld(); function createHelloWorld(f) { return { print() { f.log(HELLO_WORLD); } } } @@ -187,7 +187,7 @@ createHelloWorld(console).print(); function createHelloWorld() { return { print(console) { console.log(HELLO_WORLD); } }; } @@ -200,7 +200,7 @@ createHelloWorld().print(console); const HelloWorld = (function createHelloWorld() { return { print(console) { console.log(HELLO_WORLD); } }; })(); @@ -214,7 +214,7 @@ HelloWorld.print(console); ```js // This is a contrived case as IO is all about side-effect function helloWorld() { return HELLO_WORLD'; } // usage console.log(helloWorld()); @@ -223,7 +223,7 @@ console.log(helloWorld()); #### Side-effect on binding #### ```js function helloWorld(console) { return console.log(HELLO_WORLD); } // usage helloWorld(console); @@ -233,7 +233,7 @@ helloWorld(console); #### early binding #### ```js function helloWorld(f) { return () => f.log(HELLO_WORLD); } // usage helloWorld(console)(); @@ -242,7 +242,7 @@ helloWorld(console)(); ##### Late Binding ##### ```js function helloWorld() { return (f) => f.log(HELLO_WORLD); } // usage helloWorld()(console); -
leonyu revised this gist
May 16, 2016 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ * All implementations assume `console.log` is a static function with side-effect. * All implementations assume `Hello world!!!` is a constant and does not need to be abstracted, does not need to be separated into a variable, and thus should always be inlined. ## Declarative ## ```jsx -
leonyu revised this gist
May 16, 2016 . 1 changed file with 21 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -10,13 +10,13 @@ React.render(HelloWorld, doment.body) ## Imperative ## ### Procedural ### #### Direct invocation #### ```js console.log('Hello world!!!'); // usage // none - procedural code ``` #### Subroutine #### ```js function printHelloWorld() { console.log('Hello world!!!'); } @@ -27,7 +27,7 @@ printHelloWorld(); ### Static-typed object-oriented ### #### Static #### ##### Static method ##### ```js class HelloWorld { static print() { console.log('Hello world!!!'); @@ -38,7 +38,7 @@ HelloWorld.print(); ``` ##### Static invocation from method ##### ```js class HelloWorld { print() { console.log('Hello world!!!'); @@ -50,7 +50,7 @@ new HelloWorld().print() #### Injection-based #### ##### constructor injection ##### ```js class HelloWorld { constructor(console) { this.console = console; @@ -64,7 +64,7 @@ new HelloWorld(console).print(); ``` ##### Parameter Injection ##### ```js class HelloWorld { print(console) { console.log('Hello world!!!'); @@ -75,7 +75,7 @@ new HelloWorld().print(console); ``` ##### Autowired Injection ##### ```js class HelloWorld { $console; print(console) { @@ -87,7 +87,7 @@ Singleton.get(HelloWorld).print(console); ``` ### Inheritance ### #### Classical Inheritance #### ```js // following code would not work as Console is not publically initializable class HelloWorld extends Console { print() { @@ -99,7 +99,7 @@ new HelloWorld().log(); ``` #### Prototypical inheritance #### ```js let myConsole = Object.create(console); myConsole.print = function () { this.log('Hello world!!!'); @@ -109,7 +109,7 @@ myConsole.print(); ``` #### Old-school class pattern #### ```js // following code would not work as Console is not publically initializable function HelloWorld() { } @@ -123,7 +123,7 @@ new HelloWorld().log(); ### Dynamic-typed object-oriented ### #### Mixin #### ##### Static invocation ##### ```js const HelloWorldMixin = { printHelloWorld() { console.log('Hello World!!!'); @@ -135,7 +135,7 @@ obj.printHelloWorld(); ``` ##### Parameter injection ##### ```js const HelloWorldMixin = { printHelloWorld(console) { console.log('Hello World!!!'); @@ -147,7 +147,7 @@ obj.printHelloWorld(console); ``` ##### Mixins on native methods ##### ```js const HelloWorldMixin = { printHelloWorld() { console.log('Hello World!!!'); @@ -159,7 +159,7 @@ console.printHelloWorld(); ``` ### Monkey-pactching method ### ```js console.printHelloWorld = function() { this.log('Hello world!!!'); } @@ -169,7 +169,7 @@ console.printHelloWorld(); ### Factory / Builder ### #### Constructor Injection #### ```js function createHelloWorld(f) { return { print() { @@ -182,7 +182,7 @@ createHelloWorld(console).print(); ``` #### Parameter Injection #### ```js function createHelloWorld() { return { print(console) { @@ -195,7 +195,7 @@ createHelloWorld().print(console); ``` #### IIFE / old-school module pattern #### ```js const HelloWorld = (function createHelloWorld() { return { print(console) { @@ -210,7 +210,7 @@ HelloWorld.print(console); ## Functional programming ## ### Eager Eval ### #### Side-effect on usage #### ```js // This is a contrived case as IO is all about side-effect function helloWorld() { return 'Hello World!!!'; @@ -220,7 +220,7 @@ console.log(helloWorld()); ``` #### Side-effect on binding #### ```js function helloWorld(console) { return console.log('Hello world!!!'); } @@ -230,7 +230,7 @@ helloWorld(console); ### Lazy Eval ### #### early binding #### ```js function helloWorld(f) { return () => f.log('Hello world!!!'); } @@ -239,7 +239,7 @@ helloWorld(console)(); ``` ##### Late Binding ##### ```js function helloWorld() { return (f) => f.log('Hello world!!!'); } -
leonyu revised this gist
May 16, 2016 . 1 changed file with 10 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -209,25 +209,25 @@ HelloWorld.print(console); ## Functional programming ## ### Eager Eval ### #### Side-effect on usage #### ``` // This is a contrived case as IO is all about side-effect function helloWorld() { return 'Hello World!!!'; } // usage console.log(helloWorld()); ``` #### Side-effect on binding #### ``` function helloWorld(console) { return console.log('Hello world!!!'); } // usage helloWorld(console); ``` ### Lazy Eval ### #### early binding #### ``` -
leonyu revised this gist
May 16, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -146,7 +146,7 @@ const obj = Object.assign({}, HelloWorldMixin); obj.printHelloWorld(console); ``` ##### Mixins on native methods ##### ``` const HelloWorldMixin = { printHelloWorld() { @@ -158,7 +158,7 @@ Object.assign(console, HelloWorldMixin); console.printHelloWorld(); ``` ### Monkey-pactching method ### ``` console.printHelloWorld = function() { this.log('Hello world!!!'); -
leonyu revised this gist
May 16, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -146,7 +146,7 @@ const obj = Object.assign({}, HelloWorldMixin); obj.printHelloWorld(console); ``` ##### Monkey-patching mixins ##### ``` const HelloWorldMixin = { printHelloWorld() { @@ -158,7 +158,7 @@ Object.assign(console, HelloWorldMixin); console.printHelloWorld(); ``` #### Monkey pactching method #### ``` console.printHelloWorld = function() { this.log('Hello world!!!'); -
leonyu revised this gist
May 16, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -208,7 +208,7 @@ HelloWorld.print(console); ``` ## Functional programming ## ### Eager Eval ### #### Side-effect on binding #### ``` // functional - eager eval - no side-effect -
leonyu revised this gist
May 16, 2016 . 1 changed file with 9 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -146,15 +146,6 @@ const obj = Object.assign({}, HelloWorldMixin); obj.printHelloWorld(console); ``` ##### Target Mixin ##### ``` const HelloWorldMixin = { @@ -167,6 +158,15 @@ Object.assign(console, HelloWorldMixin); console.printHelloWorld(); ``` #### Monkey pactching #### ``` console.printHelloWorld = function() { this.log('Hello world!!!'); } // usage console.printHelloWorld(); ``` ### Factory / Builder ### #### Constructor Injection #### ``` -
leonyu revised this gist
May 16, 2016 . 1 changed file with 21 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -9,10 +9,19 @@ React.render(HelloWorld, doment.body) ## Imperative ## ### Procedural ### #### Direct invocation #### ``` console.log('Hello world!!!'); // usage // none - procedural code ``` #### Subroutine #### ``` function printHelloWorld() { console.log('Hello world!!!'); } // usage printHelloWorld(); ``` ### Static-typed object-oriented ### @@ -28,7 +37,7 @@ class HelloWorld { HelloWorld.print(); ``` ##### Static invocation from method ##### ``` class HelloWorld { print() { @@ -65,7 +74,7 @@ class HelloWorld { new HelloWorld().print(console); ``` ##### Autowired Injection ##### ``` class HelloWorld { $console; @@ -77,7 +86,7 @@ class HelloWorld { Singleton.get(HelloWorld).print(console); ``` ### Inheritance ### #### Classical Inheritance #### ``` // following code would not work as Console is not publically initializable class HelloWorld extends Console { @@ -125,7 +134,7 @@ const obj = Object.assign({}, HelloWorldMixin); obj.printHelloWorld(); ``` ##### Parameter injection ##### ``` const HelloWorldMixin = { printHelloWorld(console) { @@ -146,7 +155,7 @@ console.printHelloWorld = function() { console.printHelloWorld(); ``` ##### Target Mixin ##### ``` const HelloWorldMixin = { printHelloWorld() { @@ -159,7 +168,7 @@ console.printHelloWorld(); ``` ### Factory / Builder ### #### Constructor Injection #### ``` function createHelloWorld(f) { return { @@ -172,7 +181,7 @@ function createHelloWorld(f) { createHelloWorld(console).print(); ``` #### Parameter Injection #### ``` function createHelloWorld() { return { @@ -200,7 +209,7 @@ HelloWorld.print(console); ## Functional programming ## ### eager eval ### #### Side-effect on binding #### ``` // functional - eager eval - no side-effect function helloWorld(console) { @@ -209,7 +218,7 @@ function helloWorld(console) { // usage helloWorld(console); ``` #### Side-effect on usage #### ``` no side-effect function helloWorld() { @@ -229,11 +238,11 @@ function helloWorld(f) { helloWorld(console)(); ``` ##### Late Binding ##### ``` function helloWorld() { return (f) => f.log('Hello world!!!'); } // usage helloWorld()(console); ```
NewerOlder