2007-05-17
JavaScript の関数を「引数そのまま返す化」
関数を「引数そのまま返す化」
// sonomama の s Function.prototype.s = function(arg) this(arg); // 本来の処理 return arg; // そのまま返す }
例1
hoge.method(); // ← この hoge を調べたい
alertだけ
alert(hoge);
hoge.method();
改行めんどいー。
console.logだけ
console.log(hoge); hoge.method();
改行めんどいー。
alert + そのまま返す化
alert.s(hoge).method(); // 1 ステートのまま
console.log + そのまま返す化
console.log.s(hoge).method(); // 1 ステートのまま
例2
function hoge() { // ...略... return fuga(); // ← 何が return されたかみたい }
alertだけ
function hoge() { // ...略... var result = fuga(); alert(result); return result; }
変数追加めんどいー
console.logだけ
function hoge() { // ...略... var result = fuga(); console.log(result); return result; }
変数追加めんどいー
alert + そのまま返す化
function hoge() { // ...略... return alert.s(fuga()); }
console.log + そのまま返す化
function hoge() { // ...略... return console.log.s(fuga()); }
うわー。
簡単で便利ー
トラックバック - http://d.hatena.ne.jp/amachang/20070517/1179427742
リンク元
- 169 http://reader.livedoor.com/reader/
- 140 http://blog.livedoor.jp/dankogai/archives/50833481.html
- 107 http://b.hatena.ne.jp/hotentry
- 92 http://d.hatena.ne.jp/
- 73 http://www.google.co.jp/ig?hl=ja
- 60 http://blog.livedoor.jp/dankogai/
- 54 http://b.hatena.ne.jp/
- 53 http://b.hatena.ne.jp/entrylist?sort=hot
- 39 http://www.google.com/reader/view/
- 27 http://www.google.com/search?hl=ja&lr=lang_ja&ie=UTF-8&oe=UTF-8&q=しゃっくり+止める&num=50
