ES6——generator

generator function generator

  • Ordinary function, all the way in the end

  • generator function, you can stop the middle, where it stopped, with the yield cooperate, to hand over executive power

  • yield to give up, give in, meaning abdication

  • Need to call the next () method to start the implementation, we need to meet yield stop, kick kick go one step further

  • plus a generator function front *sides can have spaces, or near or functionfunction

  • Behind the actual generation of multiple small functions to achieve stop and go

    function Show () { 
        the console.log ( 'A' ) 
        the console.log ( 'B' ) 
    } 
    Show () // normal function 
    
    function * Show2 () { 
        the console.log ( '. 1' ) 
        the yield 
        the console.log ( '2 ' ) 
    } 
    the let genObj = Show2 () 
    genObj.next () // . 1 
    genObj.next () // 2 
    genObj.next () // Finally, no result

     

 

Guess you like

Origin www.cnblogs.com/sylys/p/11649004.html