If there is this code inside a js file :
(function($) {
$.cleditor = {
...
};
...
})(jQuery);
It's the first time I see the notation $.
: so what does it mean ?
If there is this code inside a js file :
(function($) {
$.cleditor = {
...
};
...
})(jQuery);
It's the first time I see the notation $.
: so what does it mean ?
これは、新しいカスタムfunction
が jQuery コアに追加されたことを意味します。
cleditor で簡単に検索すると、それが jQuery プラグインであることがわかりますが、次のように使用することになっています。
$(selector).cleditor({options}); // where selector is either an input or textarea element
$. $.trim() のような jquery メソッドを呼び出すために使用されます(function($) { })(jQuery)
。Immediately-Invoked Function Expression
簡単に言えば、無名関数での自己呼び出しです。この表記法の詳細については、こちらを参照してください。
デフォルトでは、jQuery は「jQuery」のショートカットとして「$」を使用します。
したがって、 $(".class") または jQuery(".class") の使用は同じです。
問題を回避するためにプラグインを作成する場合、「jQuery」を関数に渡すことができます。
function($) {
//use $ writing your plugin
}(jQuery)
現在、$.cleditor オブジェクトには、カスタム プラグインの作成と組み込み機能のオーバーライドに使用されるグローバル プロパティとメソッドが含まれています。
リンクをたどると、$.cleditor の詳細がわかります
http://premiumsoftware.net/cleditor/docs/GettingStarted.html