zoukankan      html  css  js  c++  java
  • io.js的六大新特性

    io.js是nodejs的友好版的分支("friendly fork”)。它支持npm中所有的同样模块,且使用了v8最新版本的截取(v8是被node.js使用js解释器),且修复了很多的bug,下面我们将讨论这些新特性:

    在运行程序之前的预加载模块

    新的node/iojs二进制有一个新的CLI选项用于在运行程序之前预加载模型。

    -r--要求模块在启动的时候预加载

    这对于 预加载项目日志和调试你电脑中的模块很有用

    例如:

    // preload.js
    var myLogger = require('./myredislogger')('remotehost', 8678)
    
    console.log = function () {
      console.log.apply(console.log, arguments)
      myLogger.log.apply(myLogger.log, arguments)
    }
    
    console.error = function () {
      console.error.apply(console.error, arguments)
      myLogger.error.apply(myLogger.error, arguments)
    }
    
    > node -r preload.js server.js

    代码设置高效的UID/GID

    在大对数的可移植操作系统接口(posix)系统上面,高效的uid/gid(euid/egid)是程序创建文件的所有者,且程序使用其进行access检查(access checks)。现在,这些检查和设置可以在io,js中通过代码实现,例如下例:

    process.geteuid()
    process.seteuid(id)
    process.getegid()
    process.setegid(id)

    享受简单化的流创造

    当你使用io.js穿件一个新地简单化的创建(simplified creation API),你不需要在留上面设置难懂的underscore方法。

    var transform = new stream.Transform({
      transform: function(chunk, encoding, next) {
        // sets this._transform under the hood
      },
      flush: function(done) {
        // sets this._flush under the hood
      }
    });

    使用dns.lookup()的'all'参数获取所有的DNS结果

    现在在结局域名问题的时候,你可以获取所有的结果,而不是只是获得第一个或默认的结果。

    dns.lookup('localhost', {all:true}, function (err, results) {
      console.log(results)
      // [ { address: '127.0.0.1', family: 4 },
      //   { address: '::1', family: 6 },
      //   { address: 'fe80::1', family: 6 } ]
    })

    使用Buffer.indexOf() 

    这和string上面的indexOf()类似,除了对Buffers不能使用。

    在书写二进制转换器的时候buffer很有用。

    assert.deepStrictEqual() 适用于更好的测试

    The assert module commonly used in testing has a deepEqual() function which quite useful but use '==' and not '==='. assert.deepStrictEqual has the same deep recursive functionality but uses '==='.

    原文链接:https://blog.xervo.io/fun-with-iojs-6-new-features

  • 相关阅读:
    awk-使用
    缓存使用
    一致性hash-java实现treemap版
    线程同步-CountDownLatch
    一致性hash算法
    linux-配置字符串-grep
    linux-查找命令-find
    linux-网络监控命令-netstat进阶
    linux-网络监控命令-netstat初级
    linux-单引号、双引号、反引号的区别。
  • 原文地址:https://www.cnblogs.com/RachelChen/p/6606466.html
Copyright © 2011-2022 走看看