Last Updated: February 25, 2016
·
879
· voqn

Intro-code of Js library for Web and Node.js

write introduction to avail javascript library with both Browser and Node.js

;(funciton(root) {
  var myLib = {}, oldMyLib = root.myLib, deps;

  if (typeof module !== 'object' &&
      typeof require === 'function') { // on node.js
     module.exports = myLib;
     deps = require('deps');
  } else { // on browser
     root.myLib = myLib;
     deps = root.dep;
  }

  // for avoid conflicts with same name object
  myLib.noConflict = function() {
    root.myLib = oldMyLib;
    return myLib;
  };

  // ... write your library API definition ...
})(this); // "this" is global object

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside