XMen
XMen

Reputation: 30238

Hash extend by some funciton

I have a object .

reqeuest ={"_command":".login","username":"rahul","password":"12345"}

i want to add

{'on':{
                login:function(){
                    console.log("logged in ");
                },
                error:function(){
                    console.log("oops error ");
                }
            }}

So it will become like it :

{
"_command":".login","username":"rahul","password":"12345",

'on':{
                login:function(){
                    console.log("logged in ");
                },
                error:function(){
                    console.log("oops error ");
                }
            }}

what i tried is

  request=$.extend(request,{'on':{
                login:function(){
                    console.log("logged in ");
                },
                error:function(){
                    console.log("oops error ");
                }
            }});

or

  hash.extend(request,{'on':{
            login:function(){
                console.log("logged in ");
            },
            error:function(){
                console.log("oops error ");
            }
        }});

but it is not doing the what required what should i do ?

Upvotes: 0

Views: 450

Answers (2)

Eric
Eric

Reputation: 97555

request.on = {
    login: function() {
        console.log("logged in ");
    },
    error: function() {
        console.log("oops error ");
    }
}

Upvotes: 1

Edgar Villegas Alvarado
Edgar Villegas Alvarado

Reputation: 18344

You should do this:

request["on"] = {
    login:function(){
        console.log("logged in ");
    },
    error:function() {
        console.log("oops error ");
    }
};

To test it, go to Script tab in firebug, and write 'request' on the 'Watch' tab. It's working. Cheers

Upvotes: 0

Related Questions