Skip to content

Instantly share code, notes, and snippets.

@mediavrog
Created February 10, 2015 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mediavrog/be75c5940bddf6c68fa5 to your computer and use it in GitHub Desktop.
Save mediavrog/be75c5940bddf6c68fa5 to your computer and use it in GitHub Desktop.
JS bound greeting
/*
* Assuming we have some object with properties and methods
*/
var me = {
first_name: 'Ahikar',
last_name: 'Grilka',
race: 'Klingon',
email: 'AhikarGrilka@jourrapide.com',
occupation: 'Commander of Defence',
greet: function(other_person){
return 'Hi ' + other_person + '! My name is ' + this.first_name + ' ' + this.last_name + " and I'm " + this.race;
},
self_introduction: function(){
return "I work as " + this.occupation + " and you can reach me at " + this.email;
}
};
// 1) What would be the output of the code below?
me.greet("Jon Doe")
var greet_me = me.greet;
// 2) What would be return value of "greet_me" function?
greet_me("Jon Doe");
// 3) What would be the return value for race? Why?
var race = 'Vulcan';
greet_me("Jon Doe");
// 4) Which values "intro" function would return? Why?
var occupation = "Soldier";
var email = "nospamplease@star.box"
var intro = me.self_introduction;
intro.apply(me,["Jon Doe"]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment