---
title: "Discussion on \"函式設計：單一職責原則\" | Hashnode"
description: "Discussion on \"函式設計：單一職責原則\". 這是《Eloquent JavaScript》第三章 Functions，談到 Growing Function 所舉的一個例子。這個例子提供了三種寫法，很好地體現了「每支函式應該只做一件事」的精神。\n功能需求：有座牧場畜養了一群動物，種類有乳牛、雞、豬，需紀錄牠們的個別隻數。牧場主人希望數字保持三位數，若位數不足要加 0 補齊，並在數字後註明是哪種動物，方便他列印表單。像這樣：\n\n007 Cows\n\n011 Chickens\n\n003 Pigs\n\n\n關鍵知識點：\n\nwhile 迴圈：滿足條件期..."
url: "https://hashnode.com/posts/5ye95byp6kit6kii77ya5zau5lia6ig36lks5y6f5ymh/68c67b484e9a7a087b1e13d3"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [函式設計：單一職責原則](https://code-and-reflection.hashnode.dev/5ye95byp6kit6kii77ya5zau5lia6ig36lks5y6f5ymh?utm_source=hashnode&utm_medium=feed)

這是《Eloquent JavaScript》第三章 Functions，談到 Growing Function 所舉的一個例子。這個例子提供了三種寫法，很好地體現了「每支函式應該只做一件事」的精神。 功能需求：有座牧場畜養了一群動物，種類有乳牛、雞、豬，需紀錄牠們的個別隻數。牧場主人希望數字保持三位數，若位數不足要加 0 補齊，並在數字後註明是哪種動物，方便他列印表單。像這樣： 007 Cows 011 Chickens 003 Pigs 關鍵知識點： while 迴圈：滿足條件期...

Sep 14, 2025 · 2 min read · code-and-reflection.hashnode.dev  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#functions](https://hashnode.com/tag/functions)
-   [#eloquent-javascript](https://hashnode.com/tag/eloquent-javascript)
-   [#clean-code](https://hashnode.com/tag/clean-code)
-   [#beginners](https://hashnode.com/tag/beginners)

## Written by

[Michelle Chen](https://hashnode.com/@MichelleChen99)

@MichelleChen99

  
[View profile](https://hashnode.com/@MichelleChen99)

Self-taught Front-end Developer

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
