84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
我准备使用mean(mongodb+express+angular+nodejs)开发一个应用,并建立一套框架将前端与后端之间的界限模糊起来。这里遇到一个问题,有时候前后端的代码可能会放在同一个文件里,这时怎么通过javascript判断目前代码的运行环境是前段还是后端呢?
学习是最好的投资!
node.js - How to determine the running environment in javascript? -PHP Chinese website Q&A-node.js - How to determine the running environment in javascript? -PHP Chinese website Q&A
Let’s take a look and learn.
以async库为例,该库可以在浏览器或者node.js中使用
var root = this // AMD / RequireJS if (typeof define !== 'undefined' && define.amd) { define([], function () { return async; }); } // Node.js else if (typeof module !== 'undefined' && module.exports) { module.exports = async; } // included directly via <script> tag else { root.async = async; }
(function(){ var root=this, isBrowserSide=false; if(typeof window !=="undefined" && root===window){ isBrowserSide=true; } }).call(this);
node.js - How to determine the running environment in javascript? -PHP Chinese website Q&A-node.js - How to determine the running environment in javascript? -PHP Chinese website Q&A
Let’s take a look and learn.
以async库为例,该库可以在浏览器或者node.js中使用