Created
November 3, 2015 07:33
-
-
Save gokulkrishh/17129d24e80a7b18c3e4 to your computer and use it in GitHub Desktop.
Use Object.observe with polyfill
This file contains hidden or 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
/* | |
Example for Object.observe | |
Polyfill: https://github.com/MaxArt2501/object-observe | |
Detects: Add, Update, Delete properties | |
Supported Browser: http://caniuse.com/object-observe | |
*/ | |
var myObj = { | |
name: 'Gokul' | |
}; | |
Object.observe(myObj, function (changes) { | |
//changes argument will come as an array | |
//Check if changes is occured | |
if (changes[0] !== undefined) { | |
//Added new property to myObj | |
if (changes[0].type === 'add') { | |
console.log('Added a new property ----->', changes[0]); | |
} | |
//Deleted a property to myObj | |
else if (changes[0].type === 'delete') { | |
console.log('Deleted a property ----->', changes[0]); | |
} | |
//Updated a property to myObj | |
else if (changes[0].type === 'update') { | |
console.log('Updated a property ----->', changes[0]); | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment