简体   繁体   中英

How do i add a value to javascript object with a function?

bender: function () {
       var context = {
                pageName: 'Chocolatte  candy'

            },



            partials = {
                header: this.globalPartials.header,
                tabbar: this.globalPartials.tabbar
            };

          addBackbuttonIphone(); 

        $(this.el).html(templates["monkey"].render(context, partials));
        return this;
    }

});

return monkeyView;

});

in another location i have a js file that has the following function

function addBackbuttonIphone () {

    context.backButton="#more";


}

If i just add context.backButton="more" in var context directly it works . However if i use the addBackButtonIphone function to do the same it does not work . I am sure that this function is being called however, it is not giving the "#more" value to context.backButton.

Please help

Thanks

modify your function signature to accept an argument called context , like this:

function addBackbuttonIphone(context) { 
  context.backButton="#more"; 
}

then pass context into your function, like this:

addBackbuttonIphone(context);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM