Last active
August 13, 2016 16:08
-
-
Save sagaban/5976f7827958b19f3b46dc90cb7d1af3 to your computer and use it in GitHub Desktop.
This file contains 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 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