このコードも何を参照していますか?
queryString: function() {
//some code
}
WebConsole(Firefox)でテストしましたが、実行されないので、と同等ではないと思いfunction queryString() {}
ます。
それで、それは正確には何ですか?
このコードも何を参照していますか?
queryString: function() {
//some code
}
WebConsole(Firefox)でテストしましたが、実行されないので、と同等ではないと思いfunction queryString() {}
ます。
それで、それは正確には何ですか?
そこにいくつかのコードがありませんが、私はその部分が次のようなオブジェクト宣言の一部であると想定しています。
var obj = {
queryString: function() {
//some code
}
};
obj.queryString();
オブジェクトリテラルのプロパティとして関数を割り当てます。これと同等です:
var obj = {};
obj.queryString = function() { ... };
obj.queryString();
一般に、オブジェクトリテラルの構文は次のようになります。
{ key: value, otherKey: otherValue };
したがって、これがコンソールで機能しなかった理由は{}
、オブジェクトリテラルを示す文字で囲まれていなかったためです。また、この構文はオブジェクトリテラルでのみ有効です。
これはおそらく次のようなマップ/オブジェクト宣言の中にあります。
var obj = {
queryString: function() {
alert('here');
},
eggs: function() {
alert('another function');
}
};
obj.queryString();
これはラベルですhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label
var i, j;
loop1:
for (i = 0; i < 3; i++) { //The first for statement is labeled "loop1"
loop2:
for (j = 0; j < 3; j++) { //The second for statement is labeled "loop2"
if (i == 1 && j == 1) {
continue loop1;
}
console.log("i = " + i + ", j = " + j);
}
}
// Output is:
// "i = 0, j = 0"
// "i = 0, j = 1"
// "i = 0, j = 2"
// "i = 1, j = 0"
// "i = 2, j = 0"
// "i = 2, j = 1"
// "i = 2, j = 2"
// Notice how it skips both "i = 1, j = 1" and "i = 1, j = 2"
は:
、オブジェクトとそのプロパティを定義するときに使用されます。
var obj = {
queryString: function() {
//some code
}
}
これがあなたobj.queryString
の機能です。
何
queryString: function() {
//some code
}
つまり、queryString()を使用して、それが参照する関数を呼び出すことができます。この種類の参照は、JavaScriptでクラス(または疑似クラス; P)を定義する場合に一般的に使用されます。このようなもの、
var application= { namespace: {} };
application.namespace.class_name = function(){
function constructor(){
return {
exposed_property1 : property1,
exposed_property2 : property2,
...
...
}
}
//Write property/functions that you want to expose.
// Write rest of the function that you want private as function private(){}
};
したがって、コードの他の部分で、class_nameのオブジェクトを作成し、それを使用してproperty1、property2などにアクセスできます。