简体   繁体   中英

Store Javascript function result into variable

I am doing the following:

elemDrop: function(elem) {
    return elem;
},

elemAddRel: function(json) {

    var elem = this.elemDrop;

    console.log(elem);

    $(elem.item[0]).addClass('showTab').attr('rel', json.pageId);

},

However when i console.log 'elem', it just stores the entire function into a variable. How can i actually store the result of the function into the variable?

You should be able to do:

var elem = this.chunkDrop();

The use of the brackets () will trigger the function and return the result rather than setting the variable equal to the function itself.

因此,您需要通过this.chunkDrop();执行该函数this.chunkDrop();

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