churabou / mandalart-vue

0 stars 0 forks source link

javascript #4

Open churabou opened 5 years ago

churabou commented 5 years ago
    const length = 9;
    Array.apply(null, {length}).map(Number.call, Number).map((index) => `item ${index}`)
    // ["item 0", "item 1", "item 2", "item 3", "item 4", "item 5", "item 6", "item 7", "item 8"]
churabou commented 5 years ago
churabou commented 5 years ago
  getProducts (cb) {
    setTimeout(() => cb(_products), 100)
  },

  buyProducts (products, cb, errorCb) {
    setTimeout(() => {
      // simulate random checkout failure.
      (Math.random() > 0.5 || navigator.userAgent.indexOf('PhantomJS') > -1)
        ? cb()
        : errorCb()
    }, 100)
  }

swiftみたいに引数にコールバックできる。

churabou commented 5 years ago
[...Array(10)].map((_,i) => `item${i}`)

乱数

Math.floor(Math.random()*10)

random()の括弧よく忘れる