Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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