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

标签 javascript node.js

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/

相关文章:

javascript - 在 JavaScript 中传递数据

javascript - AJAX 帖子和页面刷新

javascript - 语法错误: Unexpected token >

javascript - Passport req.user 未定义。 deserializeUser 返回一个有效的用户

java - Angularjs调用java函数

javascript - 如何在绘制之前获取 D3.js 元素的尺寸?

javascript - NodeJs 堆 js 模块 : Heap is not a constructor

node.js - 根据项目自动切换到正确的Node版本

JavaScript效率: big object vs many arrays

javascript - google map map.fitBounds() 和 bounds.extend() 未按预期工作。