Created
May 26, 2017 00:00
-
-
Save anthonybrown/1faa0cc1176566e279b160530622674e to your computer and use it in GitHub Desktop.
New and Window Binding // source https://jsbin.com/vegusa
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<meta name='description' content='JavaScript New & Window Binding'> | |
<title>New and Window Binding</title> | |
</head> | |
<body> | |
<div id='msg'></div> | |
<script id="jsbin-javascript"> | |
/* | |
- Implicate Binding | |
- Explicit Binding | |
- new Binding | |
- window Binding | |
*/ | |
document.addEventListener("DOMContentLoaded", function(e) { | |
// New Binding | |
var msg = document.getElementById('msg'); | |
var Animal = function (color, name, type) { | |
// this = {} | |
this.color = color; | |
this.name = name; | |
this.type = type; | |
}; | |
Animal.prototype.greet = function () { | |
console.log(`My name is ${this.name} and I am a ${this.color} ${this.type}!`); | |
return msg.innerHTML += `My name is ${this.name} and I am a ${this.color} ${this.type}`; | |
}; | |
var zebra = new Animal('black and white', 'Zorro', 'Zebra'); | |
msg.innerHTML += zebra.greet(); | |
// Window Binding | |
// var sayAge = function() { | |
/* using strict mode */ | |
/* throws an immediate error.*/ | |
// 'use strict'; | |
// console.log(this.age); | |
// return msg.innerHTML += '<br>'+this.age + '<br>'; | |
// }; | |
// var me = { | |
// age: 33 | |
// }; | |
// sayAge(); | |
// window.age = 50; | |
// sayAge(); | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">/* | |
- Implicate Binding | |
- Explicit Binding | |
- new Binding | |
- window Binding | |
*/ | |
document.addEventListener("DOMContentLoaded", function(e) { | |
// New Binding | |
var msg = document.getElementById('msg'); | |
var Animal = function (color, name, type) { | |
// this = {} | |
this.color = color; | |
this.name = name; | |
this.type = type; | |
}; | |
Animal.prototype.greet = function () { | |
console.log(`My name is ${this.name} and I am a ${this.color} ${this.type}!`); | |
return msg.innerHTML += `My name is ${this.name} and I am a ${this.color} ${this.type}`; | |
}; | |
var zebra = new Animal('black and white', 'Zorro', 'Zebra'); | |
msg.innerHTML += zebra.greet(); | |
// Window Binding | |
// var sayAge = function() { | |
/* using strict mode */ | |
/* throws an immediate error.*/ | |
// 'use strict'; | |
// console.log(this.age); | |
// return msg.innerHTML += '<br>'+this.age + '<br>'; | |
// }; | |
// var me = { | |
// age: 33 | |
// }; | |
// sayAge(); | |
// window.age = 50; | |
// sayAge(); | |
}); | |
</script></body> | |
</html> |
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
/* | |
- Implicate Binding | |
- Explicit Binding | |
- new Binding | |
- window Binding | |
*/ | |
document.addEventListener("DOMContentLoaded", function(e) { | |
// New Binding | |
var msg = document.getElementById('msg'); | |
var Animal = function (color, name, type) { | |
// this = {} | |
this.color = color; | |
this.name = name; | |
this.type = type; | |
}; | |
Animal.prototype.greet = function () { | |
console.log(`My name is ${this.name} and I am a ${this.color} ${this.type}!`); | |
return msg.innerHTML += `My name is ${this.name} and I am a ${this.color} ${this.type}`; | |
}; | |
var zebra = new Animal('black and white', 'Zorro', 'Zebra'); | |
msg.innerHTML += zebra.greet(); | |
// Window Binding | |
// var sayAge = function() { | |
/* using strict mode */ | |
/* throws an immediate error.*/ | |
// 'use strict'; | |
// console.log(this.age); | |
// return msg.innerHTML += '<br>'+this.age + '<br>'; | |
// }; | |
// var me = { | |
// age: 33 | |
// }; | |
// sayAge(); | |
// window.age = 50; | |
// sayAge(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment