MVC ,utility模組(工具), 常數(不會變動的資料)


Posted by mijouhsieh on 2023-04-16

utility /juːˈtɪl.ə.ti/

宣告一個叫 utility 的模組來存放小工具(洗牌函式),這個 utility 概念像是外掛函式庫:

const utility = {
  getRandomNumberArray (count) {
    const number = Array.from(Array(count).keys())
    for (let index = number.length - 1; index > 0; index--) {
      let randomIndex = Math.floor(Math.random() * (index + 1))
        ;[number[index], number[randomIndex]] = [number[randomIndex], number[index]]
    }
    return number
  }
}

Symbols 常數。習慣上將字首大寫以表示,儲存的資料不會變動。

圖片來源存在 Symbols 變數中,在文件開頭宣告花色陣列:

const Symbols = [
  'https://assets-lighthouse.alphacamp.co/uploads/image/file/17989/__.png', // 黑桃
  'https://assets-lighthouse.alphacamp.co/uploads/image/file/17992/heart.png', // 愛心
  'https://assets-lighthouse.alphacamp.co/uploads/image/file/17991/diamonds.png', // 方塊
  'https://assets-lighthouse.alphacamp.co/uploads/image/file/17988/__.png' // 梅花
]

#MVC #utility 模組 #不變動資料







Related Posts

淺拷貝與深拷貝

淺拷貝與深拷貝

人性較量Day06~量化資訊

人性較量Day06~量化資訊

React-[基礎篇]- React如何處理事件

React-[基礎篇]- React如何處理事件


Comments