Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.78 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  2. "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4.  
  5. <head>
  6.  
  7. <title>Test</title>
  8. <script type="text/javascript">
  9.  
  10.  
  11. function Contact() {
  12.         var state = false;
  13.         this.onStateChange = function() {};
  14.        
  15.         this.getState = function() {
  16.                 return state;
  17.         };
  18.         this.setState = function(value) {
  19.                 state = value;
  20.                 this.onStateChange();
  21.         };
  22.        
  23. }
  24.  
  25. function Connection(c1, c2) {
  26.         c1.onStateChange = function() {
  27.                 c2.setState(c1.getState());
  28.         };
  29.        
  30.         c2.onStateChange = function() {
  31.                 c1.setState(c2.getState());
  32.         };
  33. }
  34.  
  35. window.onload = function() {
  36.         var ac1 = new Contact();
  37.         var ac2 = new Contact();
  38.        
  39.         var conn1 = new Connection(ac1, ac2);
  40.        
  41.         ac1.setState(true);
  42.         alert(ac2.getState());
  43. }
  44. </script>
  45. </head>
  46.  
  47. <body>
  48.  
  49. </body>
  50.  
  51. </html>