如何将JSON转换为用作创建对象的Class

时间:2011-08-09 14:16:11

标签: javascript json oop

这是我的JSON

var nodeclienthash={
  socket:null,
  init : function() {
    // initialize socket.io
    this.socket = new io.Socket(this.config.host, {port: this.config.port, rememberTransport: false});
 }
};

现在我想只创建两个对象,我该如何创建呢?

1 个答案:

答案 0 :(得分:2)

function NodeClientHash() {
    this.socket = null;
    this.init = function() {
        this.socket = new io.Socket(this.config.host, {port: this.congig.port, rememberTransport: false});
    }
}

var client = new NodeClientHash();