Skip to content

Instantly share code, notes, and snippets.

@roneesh
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roneesh/1d64cc9009281790496d to your computer and use it in GitHub Desktop.
Save roneesh/1d64cc9009281790496d to your computer and use it in GitHub Desktop.
Object.observe trial
<html>
<head>
<style>
.hook {
width: 200px;
height: 200px;
background-color: rgba(0,0,0, 0.5);
border-radius: 15px;
color: white;
font-family: sans-serif;
padding: 20px;
}
</style>
</head>
<body>
<div id="hookOne" class="hook"></div>
<script>
var person = {
name: 'Dude',
age: '100',
profession :'Welder'
},
hook = document.getElementById('hookOne');
function render(location, object) {
location.innerHTML = '';
var newBio = document.createElement('div');
for (property in object) {
var newBioTag = document.createElement('p'),
newBioLine = document.createTextNode(property.toUpperCase() + ': ' + object[property])
newBioTag.appendChild(newBioLine);
newBio.appendChild(newBioTag);
};
location.appendChild(newBio);
}
Object.observe(person, function(changes) {
render(hook, person);
});
render(hook, person);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment