Last active
December 19, 2015 16:48
-
-
Save thomasboyt/5986556 to your computer and use it in GitHub Desktop.
proxies vs observers
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
| <!-- Works in Chrome with "Experimental JavaScript Features" flag enabled --> | |
| <html> | |
| <body> | |
| <span id="test"></span> | |
| <script> | |
| var foo = {}; | |
| Object.observe(foo, function(records) { | |
| records.forEach(function(record) { | |
| document.getElementById(record.name).innerHTML = record.object[record.name]; | |
| }); | |
| }); | |
| foo['test'] = "Hello."; | |
| </script> | |
| </body> | |
| </html> |
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
| <!-- Works in Firefox --> | |
| <html> | |
| <body> | |
| <span id="test"></span> | |
| <script> | |
| var foo = new Proxy({}, { | |
| set: function(target, name, val) { | |
| document.getElementById(name).innerHTML = val; | |
| target[name] = val; | |
| } | |
| }); | |
| foo['test'] = "Hello."; | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment