node.js中的path.join方法使用说明
方法说明:
将多个参数组合成一个path(详细请看例子)
语法:
path.join([path1],[path2],[...])
由于该方法属于path模块,使用前需要引入path模块(varpath=require(“path”))
例子:
path.join('/foo','bar','baz/asdf','quux','..')
//returns
'/foo/bar/baz/asdf'
path.join('foo',{},'bar')
//throwsexception
TypeError:Argumentstopath.joinmustbestrings
源码:
//windowsversion
exports.join=function(){
functionf(p){
if(!util.isString(p)){
thrownewTypeError('Argumentstopath.joinmustbestrings');
}
returnp;
}
varpaths=Array.prototype.filter.call(arguments,f);
varjoined=paths.join('\\');
//Makesurethatthejoinedpathdoesn'tstartwithtwoslashes,because
//normalize()willmistakeitforanUNCpaththen.
//
//Thisstepisskippedwhenitisveryclearthattheuseractually
//intendedtopointatanUNCpath.Thisisassumedwhenthefirst
//non-emptystringargumentsstartswithexactlytwoslashesfollowedby
//atleastonemorenon-slashcharacter.
//
//Notethatfornormalize()totreatapathasanUNCpathitneedsto
//haveatleast2components,sowedon'tfilterforthathere.
//ThismeansthattheusercanusejointoconstructUNCpathsfrom
//aservernameandasharename;forexample:
//path.join('//server','share')->'\\\\server\\share\')
if(!/^[\\\/]{2}[^\\\/]/.test(paths[0])){
joined=joined.replace(/^[\\\/]{2,}/,'\\');
}
returnexports.normalize(joined);
};
热门推荐
1 泰迪狗狗如何训练
3 狗狗训练图
5 狗狗训练方法
6 训练狗狗不咬人
8 敏捷训练狗狗
10 训练狗狗吃饭
11 泰迪狗狗训练
12 狗狗从多大开始训练
13 狗狗训练学校费用
14 怎么去训练狗狗
15 狗狗训练狗狗
16 狗狗训练教程
17 训练狗狗装死
18 泰迪狗狗的训练方法