0

Here is my JSON

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

For now i want to create only two object , how should i create that ?

4
  • 1
    This is not JSON, this is JavaScript. Commented Aug 9, 2011 at 14:18
  • @cdhowie JSON = JavaScript Object Notation, so, Rahul is right =)! Commented Aug 9, 2011 at 14:26
  • 1
    No, he is not. The function() construct, the var keyword, the = token, statements... none of these are valid JSON. Do not confuse the JavaScript object literal syntax with the JSON specification. All valid JSON strings are valid JavaScript expressions; not all valid JavaScript expressions are valid JSON strings. Commented Aug 9, 2011 at 14:27
  • So what about JSON-callbacks? Don't you consider them valid JSONs? Commented Aug 9, 2011 at 14:38

1 Answer 1

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();
Sign up to request clarification or add additional context in comments.

2 Comments

it means i have toconvert my hash to function
Yes! But, actually, when you use this in functions, combined with the new keyword, you could call this a class =)!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.