node.js中的path.join方法使用说明

前端之家收集整理的这篇文章主要介绍了node.js中的path.join方法使用说明前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

方法说明:

将多个参数组合成一个 path (详细请看例子)

语法:

代码如下:

由于该方法属于path模块,使用前需要引入path模块(var path= require(“path”) )

例子:

代码如下:

源码:

代码如下:
var paths = Array.prototype.filter.call(arguments,f);
var joined = paths.join('\');

// Make sure that the joined path doesn't start with two slashes,because
// normalize() will mistake it for an UNC path then.
//
// This step is skipped when it is very clear that the user actually
// intended to point at an UNC path. This is assumed when the first
// non-empty string arguments starts with exactly two slashes followed by
// at least one more non-slash character.
//
// Note that for normalize() to treat a path as an UNC path it needs to
// have at least 2 components,so we don't filter for that here.
// This means that the user can use join to construct UNC paths from
// a server name and a share name; for example:
// path.join('//server','share') -> '\\server\share\')
if (!/^[\\/]{2}[^\\/]/.test(paths[0])) {
joined = joined.replace(/^[\\/]{2,}/,'\');
}

return exports.normalize(joined);
};

原文链接:https://www.f2er.com/nodejs/57042.html

猜你在找的Node.js相关文章