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() {
      function Foo() {
      }
      Object.defineProperty(Foo.prototype, "myProp", {
        get: function() {
          var obj = { bar: 3 };
          Object.defineProperty(this, "myProp", {
            get: function() {
              return obj;
            },
            set: function(value) {
              obj = value;
            }
          });
          return obj;
        }
      });
      
      var f1 = new Foo();
      var f2 = new Foo();
      display("f1.myProp.bar before: " + f1.myProp.bar);
      f1.myProp.bar = 4;
      display("f1.myProp.bar after: " + f1.myProp.bar);
      display("f2.myProp.bar: " + f2.myProp.bar);
      
      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