Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 651
hrishikeshp19 Avatar asked Sep 05 '26 14:09

hrishikeshp19


1 Answers

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;
like image 94
zzzzBov Avatar answered Sep 07 '26 03:09

zzzzBov