new function() 使用

    var zwk = function(){
        var def = {
            name:'k',
            setName:function(name){
                this.name = name;
                return this;
            },
            getName:function(){
                console.log('getName:'+this.name);
                return this;
            }
        }
        return def;
    }

    new zwk()
    .setName('kelvin')
    .getName()

输出结果:
这里写图片描述

你可能感兴趣的:(JavaScript)