singleton(id, mdl, fn)
确保包装模块只有一个实例实例化。 类似于 #ifndef/#define pragmas in C
Parameters:
Name Type Description id
string 模块存储在global namespace
mdl
Object 传递给每个 node/browserify 模块
fn
function 函数的模块变量,它包装了模块
1t 中文文档教程
1t
确保只有一个模块实例存在于服务器端或浏览器中。
1t == one ton == a singleton
var singleton = require('1t');
// #ifndef
singleton('__FOO__', module, function () {
// #define __FOO__
var path = require('path');
exports.hello = 'world';
exports.filename = path.basename(__filename);
})
// #endif
Installation
npm install 1t
API
License
MIT的代码
1t
Ensures that only one instance of your module exists either serverside or in the browser.
1t == one ton == a singleton
var singleton = require('1t');
// #ifndef
singleton('__FOO__', module, function () {
// #define __FOO__
var path = require('path');
exports.hello = 'world';
exports.filename = path.basename(__filename);
})
// #endif
Installation
npm install 1t
API
singleton(id, mdl, fn)
Ensures that only one instance for the wrapped module is instantiated. Works similar to #ifndef/#define pragmas in C
Parameters:
Name Type Description id
string the unique id under which the module is stored in the global namespace
mdl
Object the module variable that is passed to each node/browserify module
fn
function function that wraps the code of the module
License
MIT