Skip to content

Instantly share code, notes, and snippets.

@sagaban
Last active August 13, 2016 16:08
Show Gist options
  • Save sagaban/5976f7827958b19f3b46dc90cb7d1af3 to your computer and use it in GitHub Desktop.
Save sagaban/5976f7827958b19f3b46dc90cb7d1af3 to your computer and use it in GitHub Desktop.
var fullname = 'John Doe';
var obj = {
fullname: 'Colin Ihrig',
prop: {
fullname: 'Aurelio De Rosa',
getFullname: function() {
return this.fullname;
}
}
};
console.log(obj.prop.getFullname());
var test = obj.prop.getFullname;
console.log(test());
console.log("-----");
console.log(test.call(this));
console.log(test.call(obj));
console.log(test.call(obj.prop));
console.log("-----");
var boundFuction1 = test.bind(obj);
var boundFuction2 = test.bind(obj.prop);
console.log(boundFuction1());
console.log(boundFuction2());
/*
Aurelio De Rosa
John Doe
-----
John Doe
Colin Ihrig
Aurelio De Rosa
-----
Colin Ihrig
Aurelio De Rosa
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment