-
-
Save pamplonafala/6bba4d07978edf258d64c61c5408ff33 to your computer and use it in GitHub Desktop.
literal objects(literals) vs constructor functions vs factory functions
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 characters
| // Factory function/method | |
| function factoryFunction (){ | |
| return { | |
| field : 'value', | |
| method : function() { return 5; } | |
| } | |
| } | |
| const myNewObjectA = factoryFunction(); | |
| // Constructor Function | |
| function constructorFunction (){ | |
| this.field : 'value', | |
| this.method : function() { return 5; } | |
| } | |
| const myNewObjectB = new constructorFunction(); | |
| // Object Literal | |
| const myNewObjectC = { | |
| field : 'value', | |
| method : function() { return 5; } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment