Javascript - Dynamically change the contents of a function
<p>I have this function that (on page load) changes my margin using the "css" jQuery method...</p>

<pre><code>function page_change() {
  var h = window.location.hash;

  switch (h) {
    case 'home':
      $('.page-slide-box').css({marginLeft: 0});
      break;
    case 'history':
      $('.page-slide-box').css({marginLeft: '-820px'});
      break;
    // more cases here.....
  }
}
</code></pre>

<p>...but after the page is loaded, I'd like to <strong>animate</strong> the change instead. I was thinking I could alter the existing function using replace() (rather than writing another redundant function), like so:</p>

<pre><code>window.onhashchange = function() {
  var get = page_change.toString();
  var change = get.replace(/css/g, ￼'animate');
  page_change();
}
</code></pre>

<p>This successfully changes all instances of "css" to "animate" in my page_change() function. How do I get this function to change dynamically once I've replaced the strings? Or is this just a bad idea?</p>
