title: Simplest self-modifying function in JavaScript?
body: <p>I would like to research and fiddle around with self-modifying functions and knowing that JavaScript has <code>eval</code> and other interesting reflection-ish features, like making a function print its body from the inside, I figured I would like to do some self-modifying function tests with JavaScript.</p>
  
  <p>I want to have a simple function, that, when called, modifies itself according to what ever, any rule.</p>
  
  <p>Like maybe some function could first do a simple <code>console.log</code> and the next time it is called it would do <code>alert</code> instead. This can be obviously achieved with an <code>if</code>, but what I am looking for here is that the actual physical function should first look like this:</p>
  
  <pre><code>function selfm()
  {
      console.log('hello')
      // + modify self here somehow
  }
  </code></pre>
  
  <p>And after the first call:</p>
  
  <pre><code>function selfm()
  {
      alert('hello')
  }
  </code></pre>
  
  <p>How can I achieve this kind of behavior in its simplest form?</p>