Skip to content

Api changes between v0.8 and v0.10

koichik edited this page Mar 11, 2013 · 3 revisions

このページを編集する場合は、できるだけ詳しく記述してください。サンプル歓迎!

Changed

  • Streams インタフェース

    • Readable, Writable, Duplex, そして Transform ベースクラスが追加されました。
    • Readable ストリームは、すぐに 'data' イベントを発する代わりに、read() メソッドを使用します。
    • 'data' イベントハンドラを追加するか、pause() または resume() を呼び出すと、"旧モード" に切り替わります。
      • これは、data イベントハンドラはそれが追加されるより前の最初のチャンクを失わないことと、pause() はもはや単なるアドバイスではないことを意味します。
    • もしデータを消費しなければ、ストリームはずっと中断状態となります。そして 'end' イベントは決して発生しません。
  • uv_after_work_cb のシグネチャが変更され、状態を示すために2番目の整数型の引数を受け取るようになりました。後方互換性のため、第4引数は明示的に uv_queue_work にキャストします。

  • process.nextTick は現在の tick が終わった後、現在のスタックが巻き戻された直後に発生します。もし再帰処理のために nextTick を使っているなら、代わりに setImmediate を使ってください。

  • -p --print コマンドライン引数は -e --eval を意味します。

  • url: 解析されたオブジェクトは常に全てのプロパティを含み、使われていないものには null が設定されます。例:

    // v0.8
    > url.parse('http://foo')
    { protocol: 'http:',
      slashes: true,
      host: 'foo',
      hostname: 'foo',
      href: 'http://foo/',
      pathname: '/',
      path: '/' }
    
    // 0.10
    > url.parse('http://foo')
    { protocol: 'http:',
      slashes: true,
      auth: null,
      host: 'foo',
      port: null,
      hostname: 'foo',
      hash: null,
      search: null,
      query: null,
      pathname: '/',
      path: '/',
      href: 'http://foo/' }
  • domain: エラーオブジェクトに加えられるプロパティは、スネークケースではなくキャメルケースになりました。

  • path.resolve および path.join は文字列以外の入力に対して TypeError をスローします。

  • dgram.Socket#bind() は常に非同期になりました。もし次のようなコードがあると:

    var s = dgram.createSocket('udp4');
    s.bind(1234);
    s.addMembership('224.0.0.114');

    これは次のように変更されなければなりません。

    var s = dgram.createSocket('udp4');
    s.bind(1234, function() {
      s.addMembership('224.0.0.114');
    });
  • EventEmitter のコンストラクタは様々なプロパティを設定するようになりました。それは今でも OOP 継承の親として動作しますが、正しく継承しなければなりません。「壊れた形式」の継承パターンで拡張された EventEmitter の拡張クラスは動作しないでしょう。そのスタイルの継承はこれまでもサポートされていませんでしたが、0.10 以前は実際には問題になりませんでした。

    // Broken-Style Inheritance, which has never been safe or wise
    // but is shown on many broken tutorials around the web.
    function Child() {}
    Child.prototype = new Parent(); // <-- NEVER EVER DO THIS!!
    // If you see anyone doing this in any javascript library ever,
    // post a bug telling them that it is a huge terrible mistake!
    // Inheriting from a class should not call that class's ctor
    // on the prototype shared with EVERY instance of the child class!
    
    // Correct-Style Inheritance
    function Child() {}
    Child.prototype = Object.create(Parent.prototype, {
      constructor: {
        value: Child,
        enumerable: false,
        writable: true,
        configurable: true
      }
    });
    // "Gee that's a lot of lines! I wish there was a helper method!"
    // There is.  Do this:
    util.inherits(Child, Parent);

Added

  • Streams - Readable, Writable, Duplex, そして Transform ベースクラス
  • Crypto API のストリーミングインタフェース
  • process: getgroups(), setgroups(), initgroups()
  • crypto: getHashes(), getCiphers()
  • http: response.headerSent プロパティ
  • events: 'removeListener' イベント
  • setImmediate() および clearImmediate() 関数
  • string_decoder: decoder.end() 関数と BASE-64 エンコーディング

Clone this wiki locally