RubyのObject#tapがすごく便利。tapかわいいよtap - (rubikitch loves (Emacs Ruby CUI Books))に書いてある。これを使うと、selfを返さないメソッドを使ってもチェインできる。 JavaScriptだと、こんな感じ。 Object.prototype.tap = function (fn) { fn.call(this, this); return this; }; ただ、JavaScriptだとyieldブロックがないから、少し野暮ったい。もう少し動作を限定させて、 Object.prototype.tap = function (name) { this[name].apply(this, Array.slice(arguments, 1)); return this; }; [1, 2, 3] .tap('push', 4, 5