【问题标题】:Is there any other way to create function in node.js有没有其他方法可以在 node.js 中创建函数
【发布时间】:2017-07-21 22:16:03
【问题描述】:

node.js 中有不同的 create 函数结构。 喜欢:

function abc(){
       console.log('stackoverflow');
    }

有什么新的格式可用吗?有用吗?

【问题讨论】:

  • 您的问题表明缺乏研究。 Node.js 依赖于 JavaScript,所有语法都继承自它。

标签: node.js


【解决方案1】:

方法#1

function test(){}; // function declaration

方法#2

var test = function(){};  // function expression

方法#3

var abc = function test(){};   // named function expression

方法#4

var test = (function(){        // IIFE that returns a function
  return function(){}
})();

方法#5

var Test = new Function();     // Function constructor

方法#6

var Test = a => a * 2;     // ES6 arrow function

【讨论】:

    【解决方案2】:

    这是 EcmaScript 6 之前的格式。

    然后,要声明一个函数,您可以使用:

    let result = abc => console.log('stackoverflow');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-10
      • 1970-01-01
      相关资源
      最近更新 更多