[JavaScript]如何实现一个JS脚本能在browser和NodeJs里都是用

下面是一个Common的Solution

'use strict';

    // Universal Module Definition (UMD) to support AMD, CommonJS/Node.js,
    // Rhino, and plain browser loading.
    if (typeof define === 'function' && define.amd) {
        ...
    } else if (typeof exports !== 'undefined') {
        ...
    } else {
        ...
    }

 

posted @ 2013-12-23 17:26  卜海清  阅读(890)  评论(0)    收藏  举报