jQueryの変数$は、例えば、オブジェクトと関数の両方として機能します。変数$がオブジェクトと機能の両方として働くようにする方法
// You can access object properties such as
$.fn;
// or
$.isReady;
// You can also call the function $ such as follows
$();
?
$ = function(){} // ???
$ = {}; // ???
jQueryの変数$は、例えば、オブジェクトと関数の両方として機能します。変数$がオブジェクトと機能の両方として働くようにする方法
// You can access object properties such as
$.fn;
// or
$.isReady;
// You can also call the function $ such as follows
$();
?
$ = function(){} // ???
$ = {}; // ???
ここで、Iは$
として変数dollar
を使用し、オブジェクトと関数としての両方を実装しました。
function dollar(a){
console.log(a);
}
dollar.memberFunc = function(a,b){
console.log(a+b);
}
dollar("Hello"); //as a function
dollar.memberFunc(10,20); //as a object
質問で関数とオブジェクトを区別しますが、js関数もオブジェクトです。したがって、他の関数の属性(変数、関数)を設定することができます。あなたは答えを得たいと思っています。
Javascript function is inherited from Javascript Object.
あなたは、関数を定義して、同様にそれに任意の数のプロパティを追加することができます。
var App = function(){
alert('this is a test');
}
App.version = 0.1;
App(); // runs the App method
console.log('app version is ', App.version); // prints the version which is a property of the App function itself
次のようにプロパティを追加するだけです。function $(){...}; $ .val = 5:アラート($ .val); $(); – user7951676
すべての関数はjs内のオブジェクトなので、プロパティを追加できます。 – user7951676