gpt4 book ai didi

javascript - javascript函数中void this的目的是什么

转载 作者:行者123 更新时间:2023-12-03 00:13:15 25 4
gpt4 key购买 nike

javascript函数endvoid 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;
}

任何人都知道无效目的,谢谢。

最佳答案

您拥有的是 voidoperator

The void operator evaluates the given expression 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com