javascript函数end
中void this
的作用是什么
words = ''; wordless=' ';
function say_it(word) {
return word ? smothered_mouthfuls(word) : end();
}
function smothered_mouthfuls(word) {
word = words ? wordless + word : word;
words = words + word;
return say_it;
}
function end() {
return void this,words;
}
任何人都知道无效
目的,谢谢。
最佳答案
您拥有的是 void
operator
The
void
operator evaluates the givenexpression
and then returns undefined.
与 comma operator 结合使用
The comma operator evaluates each of its operands (from left to right) and returns the value of the last operand.
return void this, words;
像这样工作
return (void this, words); // return words
实际上,对于代码来说,它看起来像是噪音,没有 this
表达式的任何意义。
如果 this
的调用调用了某些东西,那么它是必要的,否则它看起来像代码味道,其中某些代码正在执行某些没有明确提及的操作。
var words = '', wordless=' ';
function say_it(word) {
return word ? smothered_mouthfuls(word) : end();
}
function smothered_mouthfuls(word) {
word = words ? wordless + word : word;
words = words + word;
return say_it;
}
function end() {
void this; // or not
return words;
}
console.log(say_it('foo')());
console.log(say_it('bar')());
console.log(say_it('baz')());
关于javascript - javascript函数中void this的目的是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54628597/