简体   繁体   English

如何在导出函数之外获取变量

[英]How to get variable outside export function

How can I call const variable in same file but outside export const如何在同一文件中但在导出 const 之外调用 const 变量

 export const getData = async ({page="1",limit="10", createdAt="}) => {

    }

I want to crate variable like this我想像这样创建变量

const params = {
  page = "1",
  limit = "10",
  createdAt="",
}

and In export I want to call some thing like this在导出中我想调用这样的东西

 export const getData = async (params) => {

   }

the reason that I want to do like this because I want to make my code more easy to read thanks我想这样做的原因是因为我想让我的代码更容易阅读谢谢

By using a self invoking function that return a closure:通过使用返回闭包的自调用函数:

const getData = ((params) => {
    return async () =>{
        console.log(params)
    }
})({foo:'bar'})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM