兼容性
njs 是按照 ECMAScript 5.1(严格模式)创建的,带有一些 ECMAScript 6 及更高版本的扩展。 合规性仍在不断发展。
njs 特定属性和方法的定义 不符合 ECMAScript 可以在 参考 中找到。 njs 属性和方法的定义 符合 ECMAScript 可以在 ECMAScript 中找到 规范。
当前支持的功能
- 布尔值、数字、字符串、对象、数组、 函数, 函数构造函数 (0.3.6)、 和正则表达式
- ES5.1 运算符、ES7 幂运算符
- ES5.1 语句:
break,catch,continue,do while,else,finally,for,for in,if,return,switch,throw,try,var,while, 标记语句 (0.2.8) - ES6 语句:
let(0.6.0)、const(0.6.0)、async(0.7.0)await(0.7.0) -
Math性能:- ES6 的:
E,LN10,LN2,LOG10E,LOG2E,PI,SQRT1_2,SQRT2
- ES6 的:
-
Math方法:- ES6 的:
abs,acos,acosh,asin,asinh,atan,atan2,atanh,cbrt,ceil,clz32,cos,cosh,exp,expm1,floor,fround,hypot,imul,log,log10,log1p,log2,max,min,pow,random,round,sign,sin,sinh,sqrt,tan,tanh,trunc
- ES6 的:
-
Number性能:- ES6 的:
EPSILON,MAX_SAFE_INTEGER,MAX_VALUE,MIN_SAFE_INTEGER,MIN_VALUE,NEGATIVE_INFINITY,NaN,POSITIVE_INFINITY
- ES6 的:
-
Number方法:- ES6 的:
isFinite,isInteger,isNaN,isSafeInteger,parseFloat,parseInt
- ES6 的:
-
Number原型方法: -
String方法:- ES5.1 的版本:
fromCharCode - ES6 的:
fromCodePoint
- ES5.1 的版本:
-
String原型方法: -
Object方法:- ES5.1 的版本:
create(支持但不带属性列表)、defineProperties(访问器描述符支持 从 0.3.3 开始),defineProperty(访问器描述符支持 从 0.3.3 开始),freeze,getOwnPropertyDescriptor,getOwnPropertyDescriptors(0.3.1)、getOwnPropertyNames(0.3.1)、getPrototypeOf,isExtensible,isFrozen,isSealed,keys,preventExtensions,seal - ES6 的:
assign(0.3.7) - ES8 的:
entries(0.2.7)values(0.2.7)
- ES5.1 的版本:
-
Object原型方法: -
Array方法:- ES5.1 的版本:
isArray - ES6 的:
of - ES13 的:
from(0.8.0)、
- ES5.1 的版本:
-
Array原型方法: -
ArrayBuffer方法 (0.3.8):- ES6 的:
isView
- ES6 的:
-
ArrayBuffer原型方法 (0.3.8):- ES6 的:
slice
- ES6 的:
-
Typed-array构造 函数 (0.3.8):- ES6 的:
Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array
- ES6 的:
-
Typed-array原型方法 (0.3.8):- ES6 的:
copyWithin,every(0.4.4)、fill,filter(0.4.4)、find(0.4.4)、findIndex(0.4.4)、forEach(0.4.4)、includes(0.4.4)、indexOf(0.4.4)、join,lastIndexOf(0.4.4)、map(0.4.4)、reduce(0.4.4)、reduceRight(0.4.4)、reverse(0.4.4)、set,slice,some(0.4.4)、sort(0.4.2)、subarray,toString - ES13 的:
toReversed(0.8.0)toSorted(0.8.0)
- ES6 的:
-
Buffer方法 (0.4.4): -
Buffer原型方法: (0.4.4):-
compare,copy,equals,fill,includes,indexOf,lastIndexOf,readIntBE,readInt8,readInt16BE,readInt32BE,readIntLE,readInt8,readInt16LE,readInt32LE,readUIntBE,readUInt8,readUInt16BE,readUInt32BE,readUIntLE,readUInt8,readUInt16LE,readUInt32LE,readDoubleBE,readDoubleLE,readFloatBE,readFloatLE,subarray,slice,swap16,swap32,swap64,toJSON,toString,write,writeIntBE,writeInt8,writeInt16BE,writeInt32BE,writeIntLE,writeInt8,writeInt16LE,writeInt32LE,writeUIntBE,writeUInt8,writeUInt16BE,writeUInt32BE,writeUIntLE,writeUInt8,writeUInt16LE,writeUInt32LE,writeDoubleBE,writeDoubleLE,writeFloatBE,writeFloatLE
-
-
Promise方法 (0.3.8): -
Promise原型方法 (0.3.8):- ES6 的:
catch,finally,then
- ES6 的:
-
Function原型方法:- ES5.1 的版本:
apply,bind,call
- ES5.1 的版本:
-
RegExpprototype 访问器属性: -
RegExp原型方法: -
RegExp实例属性:-
lastIndex
-
-
RegExpES9 命名捕获组 (0.3.2) -
DataView原型方法 (0.4.4):- ES6 的:
getFloat32,getFloat64,getInt16,getInt32,getInt8,getUint16,getUint32,getUint8,setFloat32,setFloat64,setInt16,setInt32,setInt8,setUint16,setUint32,setUint8
- ES6 的:
-
Date方法:- ES5.1 的版本:
now,parse,UTC
- ES5.1 的版本:
-
Date原型方法:- ES5.1 的版本:
getDate,getDay,getFullYear,getHours,getMilliseconds,getMinutes,getMonth,getSeconds,getTime,getTimezoneOffset,getUTCDate,getUTCDay,getUTCFullYear,getUTCHours,getUTCMilliseconds,getUTCMinutes,getUTCMonth,getUTCSeconds,toDateString,toISOString,toLocaleDateString,toLocaleString,toLocaleTimeString,toTimeString,toUTCString,setDate,setFullYear,setHours,setMinutes,setMilliseconds,setMonth,setSeconds,setTime,setUTCDate,setUTCFullYear,setUTCHours,setUTCMilliseconds,setUTCMinutes,setUTCMonth,setUTCSeconds
- ES5.1 的版本:
-
JSON方法:- ES5.1 的版本:
parse,stringify
- ES5.1 的版本:
-
Symbol方法 (0.7.6):-
for,keyfor
-
- ES5.1 的
arguments对象 (0.2.5) - ES6 rest 参数语法(不支持解构) (0.2.7)
- ES5.1 全局函数:
decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,isFinite,isNaN,parseFloat,parseInt - 全局函数 (0.7.6):
atob,btoa -
Error对象:Error,EvalError,InternalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError -
clearTimeout和setTimeout功能 (0.2.0) -
File system方法:fs.accessSync(0.3.9)、fs.appendFileSync,fs.closeSync,fs.existsSync(0.8.2)、fs.FileHandle(0.7.7)、fs.fstatSync(0.7.7)、fs.lstatSync(0.7.1)fs.mkdirSync(0.4.2)、fs.openSync(0.7.7)、fs.promises.open(0.7.7)、fs.readdirSync(0.4.2)、fs.readFileSync,fs.readSync(0.7.7)、fs.realpathSync(0.3.9)、fs.renameSync(0.3.4)、fs.rmdirSync(0.4.2)、fs.symlinkSync(0.3.9)、fs.unlinkSync(0.3.9)、fs.writeFileSyncfs.writeSync(0.7.7) -
fs.promisesAPI (0.3.9)、 文件系统方法的异步版本。 -
Crypto方法 (0.2.0 版本):crypto.createHash,crypto.createHmac -
Query String方法 (0.4.3):querystring.decode,querystring.encode,querystring.escape,querystring.parse,querystring.stringify,querystring.unescape -
TextDecoder方法 (0.4.3):encoding,fatal,ignoreBOM,decode -
TextEncoder方法 (0.4.3):encode,encodeInto -
XML方法 (0.7.10):parse,xml.c14n,xml.exclusiveC14n -
zlib方法 (0.7.12):deflateRawSync,deflateSync,inflateRawSyncinflateSync - ES6 模块支持:
违约
export和 违约import语句 (0.3.0) - ES6 箭头函数 (0.3.1)
- 模板文字: 多行字符串、表达式插值、嵌套模板 (0.3.2)
- 全局对象
(0.3.3):
-
console(0.8.2) 中:error,info,log,time,timeEnd,warn -
crypto(0.7.0) 的getRandomValues,subtle.encrypt,subtle.decrypt,subtle.deriveBits,subtle.deriveKey,subtle.digestsubtle.exportKey(0.7.10)、subtle.generateKey(0.7.10)、subtle.importKey,subtle.sign,subtle.verify -
globalThis别名 (0.3.8)、 -
njs:version,version_number(0.7.4)、dump,memoryStats(0.7.8)、on(0.5.2) -
process:argv,env,pid,ppid
-
- nginx 对象方法:
-
HTTP Request:r.done(0.5.2)、r.error,r.finish,r.internalRedirect,r.log,r.return(0.5.0)、r.send(0.5.0)、r.sendBuffer(0.5.2)、r.sendHeader,r.setReturnValue(0.7.0)r.subrequest,r.warn -
Stream Session:s.allow(0.2.4)s.decline(0.2.4)s.deny(0.2.4)s.done(0.2.4)s.error,s.log,s.off(0.2.4)s.on(0.2.4)s.send(0.2.4)s.sendDownstream(0.7.8)、s.sendUpstream(0.7.8)、s.setReturnValue(0.7.0)s.warn -
Headers(0.5.1) 的append,delete,get,getAll,forEach,has,set -
Request(0.7.10) 中:arrayBuffer,headers,json,text -
Response(0.5.1) 的arrayBuffer,headers,json,text -
ngx(0.5.0 版本):fetch(0.5.1)、log -
ngx.shared(0.8.0 的 URL):add,clear,delete,freeSpace,get,has,incr,items,keys,pop,replace,set,size
-
- nginx 对象属性:
-
HTTP Request:r.args,r.headersIn,r.headersOut,r.httpVersion,r.internal,r.method,r.parent,r.rawHeadersIn(0.4.1) 的r.rawHeadersOut(0.4.1) 的r.rawVariables(0.5.0)、r.remoteAddress,r.requestBuffer(0.5.0)、r.requestText,r.responseBuffer(0.5.0)、r.responseText(0.5.0)、r.status,r.uri,r.variables(0.2.8) -
Stream Session:s.remoteAddress,s.rawVariables(0.5.0)、s.status(0.5.2)、s.variables(0.2.8) -
Periodic Session(0.8.1) 中:PeriodicSession.rawVariables,PeriodicSession.variables -
Request(0.7.10) 中:bodyUsed,cache,credentials,method,mode,url -
Response(0.5.1) 的bodyUsed,ok,redirected,status,statusText,type,url -
ngx(0.5.0 版本):build(0.8.0)、conf_file_path(0.8.0)、conf_prefix(0.7.8)、error_log_path(0.8.0)、prefix(0.8.0)、version(0.8.0)、version_number(0.8.0)、worker_id(0.8.0) -
ngx.shared(0.8.0 的 URL):capacity,name,type
-