判断js运行环境是node还是浏览器

1,342 阅读1分钟
typeof window !== 'undefined' ? console.log('前端') : console.log('后端')