开发者

get information about current commonjs implementation

Is there a standard way of detecting the implementation (node.js, rhino etc) and ideally version of that implementatio开发者_开发百科n in CommonJS.

If not, what do people do to get it?

I'm thinking something akin to the HTTP User-Agent header in the browser world.


No, but you could detect whether you're inside node, for example:

if (typeof process !== 'undefined') {
  console.log('node!');
}

If you wanted to be absolutely certain it's node:

if (typeof process !== 'undefined' 
    && process && process.versions 
    && process.versions.node) {
  console.log('node version:', process.version);
}

I can't say for other environments, (I've never used Rhino).

But to answer your question more in-depth, Node doesn't have a strict "version" of CommonJS it implements. Node hasn't been catering to CommonJS specs for a long time now (aside from the recent AMD implementation, which wasn't a full implementation anyway).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜