0

I want to load a page and, after the body tag, execute a sort based on localStorage. But myWay (no pun intended) doesn't work. Can you help me?

I have 3 sort functions, each with one of these lines:

<script>

localStorage.setItem("current_sort", "classSort()");
localStorage.setItem("current_sort", "playerSort()");
localStorage.setItem("current_sort", "ratingSort()");

</script>

<script>

myWay = localStorage.getItem("current_sort");

if (myWay === "") {myWay = "playerSort()";}

</script>

How do I load myway?

<script>
eval (myway()); //doesn't seem to work.
</script>
verlager
  • 794
  • 5
  • 25
  • 43

1 Answers1

-3

that is how we execute functions as second parameter:

localStorage.setItem("current_sort", function(){classSort()});
localStorage.setItem("current_sort", function(){nameSort()});
localStorage.setItem("current_sort", function(){ratingsort()});
Amor
  • 77
  • 2
  • 5