nginx / current / reference / njs-compatibility.html

Compatibility

njs 是根据ECMAScript 5.1(严格模式)和某些ECMAScript 6及更高版本的 extensions 创建的。合规性还在不断 Developing。

可以在Reference中找到不符合 ECMAScript 的 njs 特定属性和方法的定义。可以在ECMAScript specification中找到与 ECMAScript 兼容的 njs 属性和方法的定义。

目前支持什么

  • 布尔值,数字,字符串,对象,数组,函数,函数构造函数(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)

  • Math个属性:

  • ES6:E,LN10,LN2,LOG10E,LOG2E,PI,SQRT1_2,SQRT2

  • Math个方法:

  • ES6:abs,acos,acosh,asin,asinh,atan,atan2,atanh,cbrt,ceil,clz32,cos,cosh,exp,expm1,floor,fround,hypot,_ _21,_21,imul min,pow,random,round,sign,sin,sinh,sqrt,tan,tanh,trunc

  • Number个属性:

  • ES6:EPSILON,MAX_SAFE_INTEGER,MAX_VALUE,MIN_SAFE_INTEGER,MIN_VALUE,NEGATIVE_INFINITY,NaN,POSITIVE_INFINITY

  • Number个方法:

  • ES6:isFinite,isInteger,isNaN,isSafeInteger,parseFloat,parseInt

  • Number个实例方法:

  • ES6:toExponential(0.3.6),toFixed(0.3.6),toPrecision(0.3.6)

  • String个方法:

  • ES5.1:fromCharCode

    • ES6:fromCodePoint
  • String个实例方法:

  • ES5.1:charAt,concat,indexOf>,lastIndexOf,match,replace,search,slice,split,substr,substring,toLowerCase,trim,toUpperCase

  • Object个方法:

  • ES5.1:create(不带属性列表的支持),defineProperties(自0.3.3以来支持访问 Descriptors),defineProperty(自0.3.3以来支持访问 Descriptors),freeze,getOwnPropertyDescriptor,getOwnPropertyDescriptors(0.3.1),getOwnPropertyNames(0.3.1),getPrototypeOf,isExtensible,isFrozen isSealed,keys,preventExtensions,seal

  • Object个实例方法:

  • ES5.1:hasOwnProperty,isPrototypeOf,(0.3.0),propertyIsEnumerable,toString,valueOf

  • Array个方法:

  • ES5.1:isArray

    • ES6:of
  • Array个实例方法:

  • ES5.1:concat,every,filter,forEach,indexOf,join,lastIndexOf,map,pop,push,reduce,reduceRight,reverse,shift,slice,some,sort,splice,unshift

    • ES6:copyWithin(0.3.7),fill,find,findIndex

    • ES7:includes

  • ArrayBuffer个方法(0.3.8):

  • ES6:isView

  • ArrayBuffer个实例方法(0.3.8):

  • ES6:slice

  • Typed-array个构造函数(0.3.8):

  • ES6:Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array

  • Typed-array个实例方法(0.3.8):

  • ES6:copyWithin,fill,join,set,slice,sort(0.4.2),subarray,toString

  • Promise个方法(0.3.8):

  • ES6:reject,resolve

  • Promise个实例方法(0.3.8):

  • ES6:catch,finally,then

  • Function个实例方法:

  • ES5.1:apply,bind,call

  • RegExp个实例方法:

  • ES5.1:exec,test,toString

  • RegExp ES9 命名捕获组(0.3.2)

  • Date个方法:

  • ES5.1:now,parse,UTC

  • Date个实例方法:

  • ES5.1:getDate,getDay,getFullYear,getHours,getMilliseconds,getMinutes,getMonth,getSeconds,getTime,getTimezoneOffset,getUTCDate,getUTCDay,getUTCFullYear,getUTCHours,getUTCMilliseconds,getUTCMinutes,getUTCMonth,getUTCSeconds,_ _21,toDateString toTimeString,toUTCString,setDate,setFullYear,setHours,setMinutes,setMilliseconds,setMonth,setSeconds,setTime,setUTCDate,setUTCFullYear,setUTCHours,setUTCMilliseconds,setUTCMinutes,setUTCMonth,setUTCSeconds

  • JSON个方法:

  • ES5.1:parse stringify

  • ES5.1 arguments对象(0.2.5)

  • ES6 其余参数语法(不支持解构)(0.2.7)

  • ES5.1 全局功能:decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,isFinite,isNaN,parseFloat,parseInt

  • Error个对象:Error,EvalError,InternalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError

  • clearTimeout和setTimeout函数(0.2.0)

  • File system个方法:fs.accessSync(0.3.9),fs.appendFileSync,fs.mkdirSync(0.4.2),fs.readdirSync(0.4.2),fs.readFileSync,fs.realpathSync(0.3.9),fs.renameSync(0.3.4),fs.rmdirSync(0.4.2),fs.symlinkSync(0.3.9)

  • fs.promises API(0.3.9),文件系统方法的异步版本。

  • Crypto个方法(0.2.0):crypto.createHash,crypto.createHmac

  • ES6 模块支持:默认export和默认import语句(0.3.0)

  • ES6 箭头功能(0.3.1)

  • 模板文字:多行字符串,表达式插值,嵌套模板(0.3.2)

  • 全局对象(0.3.3):

  • globalThis别名(0.3.8),