Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Looking through the nowjs source code, I believe they do this by continuously monitoring the <code>now</code> object and pushing changes between client and server whenever they are detected. I admit I haven't fully grokked their code yet, however.</p> <p>In a browser, this would be done with some fun <code>setInterval</code> hacks.</p> <p><strong>EDIT</strong>: yes, that is indeed what they do: <a href="https://github.com/Flotype/now/blob/master/lib/client/now.js#L368">line 368</a> of the client <code>now.js</code>. They do <a href="https://github.com/Flotype/now/blob/master/lib/client/now.js#L164">some more tricks</a> so that once a new property is detected, future access to it is caught by getters and setters, but those modifications are only made every 1000 ms in a <code>setTimeout</code>.</p> <p>Another piece of evidence that this is impossible in current JavaScript is that <a href="http://wiki.ecmascript.org/doku.php?id=harmony:proxies">the proxies proposal for ECMAScript Harmony</a> is designed explicitly to enable such scenarios, implying very strongly that they can't be done currently. Recent Mozilla browsers have <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Proxy">a prototype proxies implementation</a>, if perhaps that's enough. And apparently <a href="http://code.google.com/p/v8/issues/detail?id=1543">V8 is working to add support</a>, which could be enough depending on what version of V8 Node is using these days.</p> <p><strong>EDIT2</strong>: oh cool, on the <em>server</em> side apparently nowjs does use proxies! Which likely means they are mature enough in Node for your usage. See what they do at <a href="https://github.com/Flotype/now/blob/master/lib/proxy.js">https://github.com/Flotype/now/blob/master/lib/proxy.js</a>. Or just do <code>var Proxy = require("nodejs-proxy")</code> and hope they follow the spec so you can take advantage of the documentation from MDC and elsewhere.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload