How to use global URLSearchParams in node

后端 未结 4 1995
长发绾君心
长发绾君心 2020-12-18 18:23

I am writing a (client-side) JavaScript library (a node/angular module). In this library, I make use of the URLSearchParams class.

const form = new URLSearch         


        
4条回答
  •  粉色の甜心
    2020-12-18 18:35

    If we want to support big range of nodejs versions in our application , we could use some dirty code like this :

    if(typeof URLSearchParams === 'undefined'){
        URLSearchParams = require('url').URLSearchParams;
    }
    

    Note: It is not best practice to require with a condition.

提交回复
热议问题