hrishikeshp19
hrishikeshp19

Reputation: 9028

javascript object always null

Here is my code:

myExt = {};
myExt.Panel = function (config){
    var d = document.createElement("div");
    /*Do something (a lot) with config and d here
    // a lot of code here
    */
    return
    {
        div:d,
        events:e,
        customattribs:ca
     };
}

Here is my caller:

var p = new myExt.Panel({
    id:'parent',
    events:{
        onload:function(){
            alert("onload");
        }
    },
    //more configs
});

if I do

console.log(p)

I get null. Please help me debug the problem.

Upvotes: 3

Views: 103

Answers (1)

zzzzBov
zzzzBov

Reputation: 179046

Automatic semicolon insertion has turned the return value of your function from:

return { div: d, events: 3, customattribs:ca };

into:

return;

It would be better if you stored the value you want to return in a variable, and then return that object:

var ret;
ret = {
    div: d,
    events: e,
    customattribs: ca
};
return ret;

Upvotes: 8

Related Questions