Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <script>
    (function() {
      "use strict";
      
      var obj = new Proxy({}, {
        get: function(target, name) {
          if (!(name in target)) {
            display("Getting non-existant property '" + name + "'");
            return undefined;
          }
          return target[name];
        },
        set: function(target, name, value) {
          if (!(name in target)) {
            display("Setting non-existant property '" + name + "', initial value: " + value);
          }
          target[name] = value;
        }
      });
      
      display("[before] obj.foo = " + obj.foo);
      obj.foo = "bar";
      display("[after] obj.foo = " + obj.foo);
      
      function display(msg) {
        var p = document.createElement('p');
        p.innerHTML = String(msg);
        document.body.appendChild(p);
      }
    })();
  </script>
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers