-
-
Save Bijesse/e81a862b32ebb6abc19f31e344739e15 to your computer and use it in GitHub Desktop.
This Explained // source http://jsbin.com/cemuheg
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>This Explained</title> | |
</head> | |
<body> | |
<button>Click Me!</button> | |
<script id="jsbin-javascript"> | |
var user = { | |
firstName: 'Barack', | |
lastName: 'Obama', | |
showFullName: function() { | |
alert(this.firstName + ' ' + this.lastName) | |
} | |
} | |
/* | |
This is what is claling the function to run therefore it is "this" | |
user.showFullName(); | |
*/ | |
//This doesn't work because user is not what is causing the function to run | |
//button is call the function to run therefore, button is "this" in this case | |
//$('button').click(user.showFullName); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var user = { | |
firstName: 'Barack', | |
lastName: 'Obama', | |
showFullName: function() { | |
alert(this.firstName + ' ' + this.lastName) | |
} | |
} | |
/* | |
This is what is claling the function to run therefore it is "this" | |
user.showFullName(); | |
*/ | |
//This doesn't work because user is not what is causing the function to run | |
//button is call the function to run therefore, button is "this" in this case | |
//$('button').click(user.showFullName); | |
</script></body> | |
</html> |
This file contains hidden or 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 user = { | |
firstName: 'Barack', | |
lastName: 'Obama', | |
showFullName: function() { | |
alert(this.firstName + ' ' + this.lastName) | |
} | |
} | |
/* | |
This is what is claling the function to run therefore it is "this" | |
user.showFullName(); | |
*/ | |
//This doesn't work because user is not what is causing the function to run | |
//button is call the function to run therefore, button is "this" in this case | |
//$('button').click(user.showFullName); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment