- 主题:MDN哪里可以找到js关于"require"的使用说明?
如题,谢谢。
下面这个require用法太诡异了,require参数是一个目录,居然可以访问index.js。 和perl太不一样了。不知道MDN里是否有比较规范、详细的说明,一直没找到。
[coolbar@localhost app]$ ls config/
index.js
[coolbar@localhost app]$ cat config/index.js
var config = {
local: {
mode: 'local',
port: 3000,
mongo: {
host: '127.0.0.1',
port: 27017
}
},
staging: {
mode: 'staging',
port: 4000,
mongo: {
host: '127.0.0.1',
port: 27017
}
},
production: {
mode: 'production',
port: 5000,
mongo: {
host: '127.0.0.1',
port: 27017
}
}
}
module.exports = function(mode) {
return config[mode || process.argv[2] || 'local'] || config.local;
}
[coolbar@localhost app]$ cat test.js
var config = require('./config')();
console.log(config.port);
[coolbar@localhost app]$ node test.js
3000
--
修改:saynothing FROM 218.108.104.*
FROM 218.108.104.*
Sorry,还是看Browserify的文档吧,没注意看你的代码。
【 在 saynothing 的大作中提到: 】
: 如题,谢谢。
: 下面这个require用法太诡异了,require参数是一个目录,居然可以访问index.js。 和perl太不一样了。不知道MDN里是否有比较规范、详细的说明,一直没找到。
: [coolbar@localhost app]$ ls config/
: ...................
--
修改:dhcn FROM 124.207.72.*
FROM 123.66.189.*
this is node.js and commonjs, not AMD in require.js.
and to op, node api modules
【 在 dhcn (coder) 的大作中提到: 】
: 看require.js的文档。
--
FROM 180.173.120.*
行家呀。 我正纳闷js有这么强大。
【 在 dhcn 的大作中提到: 】
: 看require.js的文档。
--
FROM 115.206.163.*
那就Browserify的文档,这个是浏览器里面的commenjs
【 在 XeCycle 的大作中提到: 】
: this is node.js and commonjs, not AMD in require.js.
: and to op, node api modules
:
--
FROM 124.207.72.*
小白顺便求问下,除了jQuery, 浏览器端还有什么比较好的js框架。
【 在 dhcn (coder) 的大作中提到: 】
: 那就Browserify的文档,这个是浏览器里面的commenjs
--
FROM 115.200.230.*
另一个回你的帖子中回了,你可以看看。
【 在 saynothing 的大作中提到: 】
: 小白顺便求问下,除了jQuery, 浏览器端还有什么比较好的js框架。
:
--
FROM 124.207.72.*