forked from KOBA789/node.js_ja
-
Notifications
You must be signed in to change notification settings - Fork 5
Api changes between v0.8 and v0.10
koichik edited this page Mar 11, 2013
·
3 revisions
このページを編集する場合は、できるだけ詳しく記述してください。サンプル歓迎!
-
- 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);
- 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 エンコーディング