Thursday, April 18, 2013

Javascript: Intro to Objects

homemade meatballs using Chef John's recipe


We finally get to use 'nouns' and 'verbs' together!!! In Javascript, let's think of 'nouns' as data such as arrays, variables, strings, etc. and 'verbs' as functions... With objects, we can finally put the two--our information and the function that uses our information, together in the same place. REUNITED AT LAST!

// here is a short code:

var blogEntry = {};

blogEntry.name = 'Jenny';
blogEntry.URL = 'thecutedork.blogspot.com';
blogEntry.blog = function(){
  console.log('Check out ' + this.name + ' at ' + this.URL + '...');
};

blogEntry.blog();

No comments:

Post a Comment