Days 37-40

in #code6 years ago

February 19th , 20th, 21st, 22nd 2018

Hello! At the ES6 course by Wes Bos I learned about generators and proxies.

Functions run from top to bottom, but with a generator you can make a function that you can start and stop or pause.You can pass information too after a time. Multiple returns offered, and we can ask for them. Yield returns multiple values.

      function* listPeople() {
          let i = 0;
          yield i;
          i++;
          yield i;
          i++;
          yield i;
           i++;
         }
  const people = listPeople();

You can also do Ajax request

  function ajax(url) {
           fetch(url).then(data => data.json()).then(data => dataGen.next(data))
         }
       function* steps() {
          console.log('fetching beers');
          const beers = yield ajax('http://api.react.beer/v2/search?q=hops&type=beer');
         console.log(beers);

        const dataGen = steps();
          dataGen.next();

Proxises

Proxies can overwrite the default behavior for many of the objects default operations.
A proxy takes two arguments: target(what is it that you want to proxy) and handler(where you specify all operations that you wish to rewrite)

 const personProxy = new Proxy(person, {
         get(target, name) {
         // console.log('someone is aksing for ', target, name);
          return target[name].toUpperCase();
      },

     set(target, name, value) {
           if(typeof value === 'string') {
            target[name] = value.trim().toUpperCase() + '8<';
        }

At the CSS grid course we did a responsive website and a formatted a webpage!

Cheers!

Coin Marketplace

STEEM 0.28
TRX 0.12
JST 0.033
BTC 70130.51
ETH 3786.12
USDT 1.00
SBD 3.78