Created
November 14, 2011 02:51
-
-
Save emkay/1363121 to your computer and use it in GitHub Desktop.
Functions this Solution
This file contains hidden or 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
| var person = { | |
| first_name: "Robert", | |
| last_name: "Barker", | |
| nick_name: "Bob", | |
| full_name: undefined, | |
| name_helper: function (short) { | |
| var that = this; // the important part | |
| var shorter_name = function () { | |
| // this to that | |
| that.full_name = that.nick_name + " " + that.last_name; | |
| }; | |
| var bigger_name = function () { | |
| // this to that | |
| that.full_name = that.first_name + " " + that.last_name; | |
| }; | |
| if (short) { | |
| shorter_name(); | |
| } else { | |
| bigger_name(); | |
| } | |
| } | |
| }; | |
| alert(person.full_name); // undefined | |
| person.name_helper(true); | |
| alert(person.full_name); // Bob Barker |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment