Skip to content

Instantly share code, notes, and snippets.

@uniquename
Created July 21, 2017 12:45
Show Gist options
  • Save uniquename/2c08adf76de2b51472cb70449e8a556d to your computer and use it in GitHub Desktop.
Save uniquename/2c08adf76de2b51472cb70449e8a556d to your computer and use it in GitHub Desktop.
/**
* Objects can have propperties and methods.
*
* Think of it as an abstraction of real world objects.
*
* There is much more to cover about objects!-)
*/
var person = {
age: 32,
gender: 'm',
name: 'John',
lastname: 'Doe',
createSalutation: function() {
var salutation;
if (this.gender == 'f') {
salutation = 'Dear Mrs. ';
} else {
salutation = 'Dear Mr. ';
}
salutation += this.name + ' ' + this.lastname;
return salutation;
}
}
// how to call a method
var mySalutation = person.createSalutation();
//console.log(someVariable);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment