Skip to content

Instantly share code, notes, and snippets.

@jpetto
Created August 31, 2012 22:40
Show Gist options
  • Save jpetto/3560291 to your computer and use it in GitHub Desktop.
Save jpetto/3560291 to your computer and use it in GitHub Desktop.
JavaScript this demo #1
var user = {
greet: function() {
// this refers to the calling object - user
console.log("Hello there " + this.name + "!");
}
};
var name;
var get_name = function() {
// this refers to the calling object - window
this.name = prompt("What's your name?");
};
get_name();
user.name = name;
user.greet();
console.log(name);
console.log(user);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment