Skip to content

Instantly share code, notes, and snippets.

@emkay
Created November 14, 2011 02:51
Show Gist options
  • Select an option

  • Save emkay/1363121 to your computer and use it in GitHub Desktop.

Select an option

Save emkay/1363121 to your computer and use it in GitHub Desktop.
Functions this Solution
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