尝试创建基于的npm模块 JavaScript function composition by chaining
这有效!
app.js
// -- runtime --
Object.defineProperties(window,
{
world:
{
set: function(w)
{
return w();
}
}
});
var pureworld = require('./app');
var log = pureworld.log;
//var world = pureworld.world;
world = (log("1"))(log("2"))(log("3"))(log("4"));
//1
//2
//3
//4
然而,
我尝试将Object.defineProperties传递给nodejs中的module.exports
app.js
var myModule = {
foo: foo,
bar: bar
};
Object.defineProperties(myModule,
{
world:
{
set: function(w)
{
return w();
}
}
});
module.exports = myModule;
这失败了。
var pureworld = require('./app');
var log = pureworld.log;
var world = pureworld.world;
world = (log("1"))(log("2"))(log("3"))(log("4"));
知道我想念的是什么吗?谢谢!