1<button id="clickme">Click Me</button>
2<script>
3 function one() {
4 alert('one clicked');
5 document.getElementById('clickme').onclick = two;
6 }
7
8 function two() {
9 alert('two clicked');
10 }
11
12 document.getElementById('clickme').onclick = one;
13</script>
1var callOne = true;
2
3function one() {
4 alert('Call one');
5}
6
7function two() {
8 alert('Call two');
9}
10
11function call(){
12 if(callOne) one();
13 else two();
14 callOne = !callOne;
15}
1var fn3 = (function() {
2 var first = true;
3 return function() {
4 first ? fn1() : fn2();
5 first = !first;
6 }
7})();
8
9function fn1() {
10 console.log(1);
11};
12function fn2() {
13 console.log(2);
14};