Created
August 31, 2017 22:43
-
-
Save claudiainbytes/fd9d245ffd7c6aa9671203015c330fa4 to your computer and use it in GitHub Desktop.
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
| //When you encapsule a function inside an object that | |
| //function is called as a method whenever you need. Example: | |
| //The object projects | |
| var projects = { | |
| "projects": [{ | |
| "title": "Project 1", | |
| "description": "Lorem ipsum dolor sit amet" | |
| }, | |
| { | |
| "title": "Project 2", | |
| "description": "Sed ut perspiciatis unde omnis" | |
| }] | |
| }; | |
| //Encapsuling the function inside the object | |
| projects.display = function(){ | |
| this.projects.forEach(function(project){ | |
| console.log("Title: " + project.title + " Description: " + project.description); | |
| }); | |
| }; | |
| //Calling the funcion as a method of the object | |
| projects.display(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment