Skip to content

Instantly share code, notes, and snippets.

@Bijesse
Forked from anonymous/index.html
Created August 17, 2016 01:10
Show Gist options
  • Save Bijesse/e81a862b32ebb6abc19f31e344739e15 to your computer and use it in GitHub Desktop.
Save Bijesse/e81a862b32ebb6abc19f31e344739e15 to your computer and use it in GitHub Desktop.
This Explained // source http://jsbin.com/cemuheg
<!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>
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