Skip to content

Instantly share code, notes, and snippets.

@flipjs
Created August 3, 2014 00:40
Show Gist options
  • Save flipjs/a5803b98f6ee247804be to your computer and use it in GitHub Desktop.
Save flipjs/a5803b98f6ee247804be to your computer and use it in GitHub Desktop.
Object.observe()
var myObject = { name : 'flipjs' }
console.log('Start observing...')
Object.observe(myObject, function(changes) {
changes.forEach(function(change) {
console.log(change.name
+ " was "
+ change.type
+ " and is now "
+ change.object[change.name])
})
})
console.log(myObject)
window.setTimeout(function(){myObject.name = 'philip'}, 1000)
window.setTimeout(function(){myObject.name = 'foobar'}, 1000)
window.setTimeout(function(){myObject.age = 42}, 1000)
window.setTimeout(function(){myObject.age = 24}, 1000)
console.log('End program.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment