だと思う...
Foo.prototype.bar = function() { // <-- 1. function
console.log("bar");
}(function() { // <-- 2. call the 1. function, passing a function argument
Foo.prototype.la = function() {
console.log("la");
};
})(); // <-- 3. tries to invoke the return value of the 1. function,
// but "undefined" was returned.
私は生命維持のための()
を使用して好きではない。私は他の演算子を好む。
Foo.prototype.bar = function() {
console.log("bar");
}
void function() {
Foo.prototype.la = function() {
console.log("la");
};
}();
元に戻り、最初の関数が関数を返すと、その関数が呼び出されたことがわかります。割り当てに使用されます
Foo.prototype.bar = function() { // <-- 1. function
console.log("bar");
return function() { alert('INVOKED'); }; // 2. return a function
}(function() { // <-- 3. call the 1. function, passing a function argument
Foo.prototype.la = function() {
console.log("la");
};
})(); // <-- 4. tries to invoke the return value of the 1. function,
// which will now call the returned function with the "alert()"
@Lasse Reichsteinにより示唆されるように、まだその左と右のオペランドを評価する二項演算子として、単項演算子を使用し、結果を返すために更新
、。
しかし、今ではbarにはその関数ではなく、その関数の結果がその括弧内にあるものと一緒に割り当てられます。ありがとうございました –
HEH - 私は正直言って私が 'function()'を好む唯一の人だと思っていました...それをした他の唯一の人はminiferです:) –
@AdamRackis:そこにはいくつかの人がいます。 :)あまりにも多くの文字が心配していなければ、私は実際に 'void'を好む。もっと目立つようだ。 –