Skip to content

Instantly share code, notes, and snippets.

@romulomourao
Created August 15, 2017 19:57
Show Gist options
  • Save romulomourao/969fedaa9e9ec18ddfe60cee4f34acf9 to your computer and use it in GitHub Desktop.
Save romulomourao/969fedaa9e9ec18ddfe60cee4f34acf9 to your computer and use it in GitHub Desktop.
JS STI // source https://jsbin.com/yayesan/1
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS STI</title>
<style id="jsbin-css">
body{
display: flex;
height: 100vh;
align-items: center;
justify-content: center;
background-color: #e7e7e7;
}
a{
background-color: #35BBFE;
color: white;
padding: 10px 30px;
display: block;
}
</style>
</head>
<body>
<a id="my-button">Click</a>
<script id="jsbin-javascript">
//this and bind
let dog = {
sound :'woof',
talk: function() {
console.log(this.sound);
}
}
let button = document.getElementById('my-button');
button.addEventListener('click', dog.talk);
//button.addEventListener('click', dog.talk.bind(dog));
</script>
<script id="jsbin-source-css" type="text/css">body{
display: flex;
height: 100vh;
align-items: center;
justify-content: center;
background-color: #e7e7e7;
}
a{
background-color: #35BBFE;
color: white;
padding: 10px 30px;
display: block;
}</script>
<script id="jsbin-source-javascript" type="text/javascript">//this and bind
let dog = {
sound :'woof',
talk: function() {
console.log(this.sound);
}
}
let button = document.getElementById('my-button');
button.addEventListener('click', dog.talk);
//button.addEventListener('click', dog.talk.bind(dog));
</script></body>
</html>
body{
display: flex;
height: 100vh;
align-items: center;
justify-content: center;
background-color: #e7e7e7;
}
a{
background-color: #35BBFE;
color: white;
padding: 10px 30px;
display: block;
}
//this and bind
let dog = {
sound :'woof',
talk: function() {
console.log(this.sound);
}
}
let button = document.getElementById('my-button');
button.addEventListener('click', dog.talk);
//button.addEventListener('click', dog.talk.bind(dog));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment