2009-05-19 7 views
4

YAHOO.lang namespaceにあるような「ヘルパー」や拡張機能を持つjQueryプラグインを知っている人はいますか?YAHOO.langのjQueryバージョン(isUndefined、isNull、isStringなど)

私のような心機能を持っている:

isNull 
isDefined 
isString 
isFunction 

私はまた、含まれていて、文字列と配列のものと同じ種類のを感謝し、STARTSWITH(私は私は、これらが書きやすいです知っていますそれらすべてを含むプラグインを探しているだけです)。

これはYAHOO.lang名前空間にはありませんが、関連する拡張機能も含まれています。つまり、フォーム要素のタイプをフレンドリ名で表したラジオボックスの値を確認します。

具体的に流暢APIのではなく、セレクタを持つプラグインが

$("input[@type=radio][@checked]") 

が再び私は、彼らが実装するのは簡単だ承知しているが、私は車輪の再発明をしたくないようなベース。

答えて

0

私は2つの新しいプラグインを自分で作成することに決めました。

Form extensions

例:

// elementExists is also added 
if ($("#someid").elementExists()) 
    alert("found it"); 

// Select box related 
$("#mydropdown").isDropDownList(); 

// Can be any of the items from a list of radio boxes - it will use the name 
$("#randomradioboxitem").isRadioBox("myvalue"); 
$("#radioboxitem").isSelected("myvalue"); 

General extensions

これらは、ISNULLなどプロトタイプ/ Mochikit機能をモデルにしているここでは、2つのプロジェクトがあります。

例:

$.isNumber(42); 

var x; 
$.isUndefined(x); 
$.isNullOrUndefined(x); 
$.isString(false); 

$.emptyString("the quick brown fox"); 
$.startsWith("the quick brown fox","the"); 
$.formatString("Here is the {0} and {2}","first","second"); 

両方がダウンロードの一部として、来る50以上のユニットテストを持っています。うまくいけば、彼らはこのページを見いだす人々に役立つでしょう。

2

jQuery 1.3.2isFunctionisArrayです(下記のスニペットを参照)。 isStringのコードはstaightforward(typeof obj === "string")ですが、isNull(obj === null)とisDefined(obj !== undefined)です - 関数を使用する代わりにそのインラインをコーディングします。

// See test/unit/core.js for details concerning isFunction. 
// Since version 1.3, DOM methods and functions like alert 
// aren't supported. They return false on IE (#2968). 
isFunction: function(obj) { 
    return toString.call(obj) === "[object Function]"; 
}, 

isArray: function(obj) { 
    return toString.call(obj) === "[object Array]"; 
}, 
+3

typeof String( "foo")=== "object" – Dinoboff

1

Underscore.jsまたは_.js(これらの機能を含むライブラリが望ましい場合)。