小编mic*_*vin的帖子

无法实现模块模式

我试图重现Douglas Crockford所着的"Javascript:The Good Parts"一书中的一些代码.我们的想法是使用闭包进行对象封装,避免使用Javascript固有的全局变量.

var serial_maker = function (  ) {

// Produce an object that produces unique strings. A
// unique string is made up of two parts: a prefix
// and a sequence number. The object comes with
// methods for setting the prefix and sequence
// number, and a gensym method that produces unique
// strings.

    var prefix = '';
    var seq = 0;
    return {
        set_prefix: function (p) {
            prefix = String(p);
        },
        set_seq: function (s) …
Run Code Online (Sandbox Code Playgroud)

javascript closures

2
推荐指数
1
解决办法
628
查看次数

标签 统计

closures ×1

javascript ×1