zoukankan      html  css  js  c++  java
  • When to use next() and return next() in Node.js

    Some people always write return next() is to ensure that the execution stops after triggering the callback.

    If you don't do it, you risk triggering the callback a second time later, which usually has devastating results. Your code is fine as it is, but I would rewrite it as:

    app.get('/users/:id?', function(req, res, next){
        var id = req.params.id;
    
        if(!id)
            return next();
    
        // do something
    });

    It saves me an indentation level, and when I read the code again later, I'm sure there is no way next is called twice.

    http://stackoverflow.com/questions/16810449/when-to-use-next-and-return-next-in-node-js

  • 相关阅读:
    DAY56
    DAY55
    DAY54
    DAY53
    DAY52
    DAY51
    DAY50
    spark1.1.0部署standalone分布式集群
    Storm流分组介绍
    Storm拓扑的并行度(parallelism)介绍
  • 原文地址:https://www.cnblogs.com/softidea/p/6740441.html
Copyright © 2011-2022 走看看