2016-05-30 18 views
-1

CODE:?任何人都知道什么是替代这段代码在IE浏览器。它工作在Firefox,铬(=()=>)

<script> 
    var expectedFunc =() => showAllSteps(); 

    function showAllSteps() { 
     alert('showAllSteps');  
     expectedFunc =() => nextStep(); 
    } 

    function nextStep() { 
     alert('nextStep');  
     expectedFunc =() => showAllSteps(); 
    } 

    function toggleFunction() { 
     expectedFunc(); 
    } 
</script> 

<button type="button" class="btn" name="showAllBtn" onclick="toggleFunction()">Show all</button> 

在此代码expectedFunc =()= > showAllSteps(); =()=>在IE中不起作用。有人知道什么是IE中这个切换的替换吗?

+1

'expectedFunc = showAllSteps;' - 你只是定义其只是调用一个函数的函数;你可能只是重新分配原来的功能。 – deceze

回答

1

这是ES6 arrow function,所以用简单的函数替换它

<script> 
 
    var expectedFunc = function() { 
 
    showAllSteps() 
 
    }; 
 

 
    function showAllSteps() { 
 
    alert('showAllSteps'); 
 
    expectedFunc = function() { 
 
     nextStep() 
 
    }; 
 
    } 
 

 
    function nextStep() { 
 
    alert('nextStep'); 
 
    expectedFunc = function() { 
 
     showAllSteps() 
 
    }; 
 
    } 
 

 
    function toggleFunction() { 
 
    expectedFunc(); 
 
    } 
 
</script> 
 

 
<button type="button" class="btn" name="showAllBtn" onclick="toggleFunction()">Show all</button>

相关问题