Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript function return as object property

I'm trying to return the value of a function as an object property (as opposed to the function itself). This is my code right now, but it breaks when I try to access option_list[0][0].label or .value within my jQuery plugin. Thoughts?

$('#new').create({
    option_list:function(){return [
        [
            {label:'option1', value:'1'},
            {label:'option2', value:'2'},
            {label:'option3', value:'3'}
        ]
    ];}
});
like image 392
Tim Avatar asked Feb 23 '23 23:02

Tim


1 Answers

You need to actually invoke the function, like so ...

$('#new').create({
    option_list:(function(){return [
        [
            {label:'option1', value:'1'},
            {label:'option2', value:'2'},
            {label:'option3', value:'3'}
        ]
    ];}())
});
like image 188
broofa Avatar answered Feb 27 '23 11:02

broofa