DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
  • Ecosystem
    • can-construct-super
    • can-define-stream
    • can-fixture
    • can-fixture-socket
    • can-jquery
    • can-stache-converters
    • can-stream
    • can-vdom
      • types
        • window
      • modules
        • ./make-document/
        • ./make-window/
    • can-view-import
    • can-zone
    • steal-stache
  • Infrastructure
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Ecosystem
  • /
  • can-vdom
  • / On this page
    • can-vdom

      module

      A browser-lite environment for Node.js or a worker thread.

      • npm package badge
      • Star
      • source

      undefined

      The can-vdom module does not export anything, but it changes the current environment to have the limited subset of browser environment behavior and functionality needed to support CanJS templates and other behavior without a native DOM.

      require("can-vdom");
      
      window === global; // true
      
      document.getElementsByTagName("body"); // [HTMLBodyElement]
      

      can-vdom decorates the environment global to include:

      • a non-functional navigator, location, and history object.
      • a limitedly functional document with basic Node behavior, event binding and dispatching.

      Shiming a browser environment

      Importing can-vdom will shim a browser-like environment into Node's globals. Use this approach to run code that expects a global window and/or document object.

      require("can-vdom");
      
      typeof window; // "object"
      
      typeof window.addEventListener; // "function"
      
      document.getElementById("foo"); // undefined
      

      Loading as a module

      If you want to prevent setting globals you can load can-vdom/make-window/make-window directly:

      var makeWindow = require("can-vdom/make-window/make-window");
      
      var myWindow = makeWindow(global);
      

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.