Giter Site home page Giter Site logo

typescript-function-generator-next-with-argument-demo's Introduction

TypeScript Function Generator Next with Argument Demo

Function generator中有一个非常迷惑人的语法:

const x = yield a+b

看起来似乎是把a+b的值赋给了x,实际上它们之间没有一毛钱关系。

当我们调用.next()的时候,代码会执行到const x = yield a+b的右段yield a+b,并且把值当作.next()的返回值返回给调用者, 然后代码就停在那里了。

直到下一次调用.next,才会继续执行const x =。但是x的值从哪里来呢?是从.next(???)的参数???传进来的,x = ???, 然后继续执行到下一个yield,把它后面的值返回出去。

这一处是我之前一直没有理解的地方。

npm install
npm run demo

typescript-function-generator-next-with-argument-demo's People

Contributors

freewind avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.