Created
February 10, 2015 08:29
-
-
Save mediavrog/be75c5940bddf6c68fa5 to your computer and use it in GitHub Desktop.
JS bound greeting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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