Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@obber
Last active September 8, 2016 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obber/3086954b40bd896b2c2869385ed46f1b to your computer and use it in GitHub Desktop.
Save obber/3086954b40bd896b2c2869385ed46f1b to your computer and use it in GitHub Desktop.
var a = function() {
console.log(this);
};
// unwrapped
console.log(this); // window
// free function invocation
a(); // window
var dianne = {
greet: function() {
console.log('i\'m awesome');
}
}
var person = {
name: 'kan',
walk: function() {
console.log(this.name + ' is walking');
return dianne;
},
greet: function() {
// assuming we do person.greet():
// this = person
// person.name => 'kan'
console.log(this.name + ' is my name');
}
}
person.walk().greet();
var Human = function(name, age) {
this.name = name;
this.age = age;
this.walk = function() {
return this.name + ' is walking';
}
}
var me = new Human('kan', 24);
var oliver = new Human('oliver', 24);
console.log(me === oliver);
function a() {};
console.log(me.walk === oliver.walk);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment