zoukankan      html  css  js  c++  java
  • nodejs难点

    1. compose

    compose(middlewares) // middleware应该是回调, 所有用async-await. middlewares = [async (ctx, next)=>{ log1, await next(), log2 }, async (ctx, next) => { log3, await next(), log4 } ]

    2. getter/setter 可以使得获取值变短

    createContext(req, res) {
            const ctx = Object.create(context)
            ctx.request = Object.create(request)
            ctx.response = Object.create(response)

            ctx.req = ctx.request.req = req
            ctx.res = ctx.response.res = res
            return ctx
        }
    这样在resposne、requet, conntext里面定义快速set值和get值。
    3. 
    function(...[first,...second])
    如果不知道多少参数可以: function(....args) //function(){ arguments }
    这是为了解决多数餐, 特别需要对第一个参数进行特别处理的。 如
    const compose1 = (...[first,...second]) => (...args) =>{
        console.log(first, second);
        let ret = first(...args)
        second.forEach(fn=>{
            ret = fn(ret)
        })
        return ret;
    }
     
  • 相关阅读:
    4、数组及字符串
    3、处理数据
    2、开始学习C++
    1、C++学习预备知识
    Django【进阶篇 】
    Django【基础篇】
    Python操作MySQL
    MySQL(二)
    python日记-使用队列写出特殊字数串
    python日记-快速排序算法
  • 原文地址:https://www.cnblogs.com/connie313/p/13369560.html
Copyright © 2011-2022 走看看