using the window object for accessing global user defined objects and using text within html for cre

Posted by timpone on Stack Overflow See other posts from Stack Overflow or by timpone
Published on 2010-04-28T20:19:20Z Indexed on 2010/04/28 22:27 UTC
Read the original article Hit count: 333

Filed under:
|

I don't do very much jquery / javascript but wanted to ask for some advice on the following piece. I have tried to cut out as much as possible. Most of this was semi-inherited code with catching a bunch of events just hardcoded in. I'd like to generalized them more by putting the object name in the html and accessing via jquery on processing (by_date, by_popularity). I retriev as string and access the object via window[current_obj]. Is this a good way to do this or am I missing something? Are there preferable ways to introduce specificity. thanks for any advice.

<script>
var by_date={};
by_date.current_page=1;
by_date.per_page=4;

var by_popularity={};
by_popularity.current_page=1;
by_popularity.per_page=4;

$(function(){
    $('.previous.active').live('click',function(){
        window[current_obj].current_page--;
        process(window[current_obj]);
    });
});

function process(game_obj){
   //will process and output new items here
}
</script>

<div class="otherContainer">
  <a class='previous active'>Prev</a><div style="display:none;">by_date</div> | <a class='next'>Next</a><div style="display:none;">by_date</div>
</div>


<div class="topPrevNextContainer">
  <a class='previous active'>Prev</a><div style="display:none;">by_popularity</div> | <a class='next'>Next</a><div style="display:none;">by_popularity</div>
</div>

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript