Search code examples
javascriptkeywordyieldyield-keyword

Javascript check yield support


I read about the yield keyword in JavaScript and I need to use it in my project. I read that this keyword has been implemented starting from a certain version of JS so I think that old browsers don't support it (right?).

Is there a way to check if the yield keyword is supported? or at least is there a way to check if the version of JS is greater or equal than the one that implements that keyword (1.7)?


Solution

  • Here's a function for checking if yield can be used.

    var can_yield = (function(){ 
        try { 
            return eval("!!Function('yield true;')().next()"); 
        } 
        catch(e) { 
            return false; 
        } 
    })();