Skip to content

Instantly share code, notes, and snippets.

@claudiainbytes
Created August 31, 2017 22:43
Show Gist options
  • Select an option

  • Save claudiainbytes/fd9d245ffd7c6aa9671203015c330fa4 to your computer and use it in GitHub Desktop.

Select an option

Save claudiainbytes/fd9d245ffd7c6aa9671203015c330fa4 to your computer and use it in GitHub Desktop.
//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