ModernWeb
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    5
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 為你自己學 JavaScript / 高見龍 {%hackmd @ModernWeb/HkqZxb98v %} ### [簡報下載](https://s.itho.me/modernweb/2020/Slides/d102.pdf) > 共筆從這開始 > 入門以上,中級未滿 ###### tags: `MW20` `語言與開發` `JavaScript` ## 延伸閱讀 [為你自己學 Git](https://gitbook.tw/) [為你自己學 Ruby on Rails](https://railsbook.tw/) [為你自己的小孩學程式設計 ](https://ithelp.ithome.com.tw/users/20065770/ironman/3808) ## 技術篇 > JavaScript 那甚麼爛設計 >世界上只有兩種語言,一種是被罵到臭頭,一種是沒人用 >就算要罵,也要是熟悉它由愛生恨,拳拳到肉的罵。 > ### 執行環境 (Execution Context) * 全域物件: * 每次開始執行的時候會有的一個物件 * 網頁: window * Node: global ```javascript= var a = 1; console.log(a == window.a) // true ``` ### 堆疊 (Stack) * 執行環境就像泡泡一樣,會一直往上疊。 * 不能無限的往上疊(EX. recursive) ==> Stack Overflow 堆疊溢位。 ### 單執行緒 * JavaScript一次只能做一件事,他是單執行緒的語言。 * Ex1 ```javascript= console.log(1); console.log(2); console.log(3); ``` > Output: 1 2 3 * Ex2 ```javascript= console.log(1); setTimeout( function(){console.log(2);}, 3000 ); console.log(3); ``` > Output: 1 3 2 * `2`會比`3`還要後面才出現 * JavaScript 本身沒有 timer,而是去調用瀏覽器內建的計時器。 * `setTimeout()`是叫程序3秒後再出來,這是一個設定的動作,他不會執行3秒鐘那麼久。 * Ex3 如果改成setTimeout只有0秒,那是不是就會跑出 1 2 3 了呢? ```javascript= console.log(1); setTimeout( function(){console.log(2);}, 0 ); console.log(3); ``` > Output: 1 3 2 實際上當 setTimeout 進去後就分離了,可見上面 ex2 的最後一條 ### Call Stack vs. Event Queue * 只要 Stack 上面還有事情要做,Event Queue 就繼續等,等到 Stack 結束 Event 才會做事。 * Ex ```javascript= console.log(1); setTimeout( function(){console.log(2);}, 0 ); console.log(3); while(1){ //發呆 無限迴圈 } ``` * 那個`2`永遠不會出現,因為Stack上面一直在做事。 * [Philip Roberts - event loop](https://www.youtube.com/watch?v=8aGhZQkoFbQ) {%youtube 8aGhZQkoFbQ %} ### 物件導向 * Javascript 沒有類別。用prototype下去做的東東。 ```javascript= function heroCreator(name, action){ // wait for implemantation } const goku = new heroCreator('悟空', '龜派氣功'); ``` * 所有物件都有`__proto__`屬性。 * Prototype Chain 原型鏈。 * 函數也是物件,每個函數都有prototype屬性。 #### new做了甚麼事 * 在泡泡裡面先建立一個空的物件。 * 把這個空物件的__proto__屬性指向heroCreator的物件。 ```javascript= function heroCreator(name, action){ this.name = name this.action = action } heroCreator.prototype.attack = function() { console.log(`${this.name}使出絕招${this.action}`); } const goku = new heroCreator('悟空', '龜派氣功'); goku.attack(); // 找不到attack,會往上找prototype ``` ### 奇怪的語法 #### 執行順序 > 先乘除後加減,由左至右 * Ex1 ```javascript= console.log(6 / 2 * 3); ``` > Output: 9 * Ex 2 ```javascript= console.log( 9 / 2 * 3); ``` > Output: 13.5 * Ex3 ```javascript= console.log(1 < 10 < 100) ; ``` > Output: True * Ex4 ```javascript= console.log(100 < 10 < 1) ``` > Output: True > `100 < 10` => `false`。執行優先順序一樣,由左至右執行 > `console.log(false < 1)` > false 就會被強制轉型轉成`0` (Javascript Corecion)。所以就合理了。 #### NaN * NaN 是一種數字, 用來表達「不是數字」或「無效的數字」 ```javascript= console.log(NaN === NaN) ``` > Output: false > 規格就這樣說R > x 或 y 是 `NaN` 一律回傳 false #### 等號 * `==` * 只會比較值,型別不一樣會做轉型。 * `==` 型別一樣會去做 `===` * `===` ## 自我成長篇 ### 做學問的方式 大部分的技術被發明出來, 是要解決特定問題的,要知道技術想解決什麼問題才去用它 要學新技術時,先想想自己是要解決什麼問題 學從難處學,用從易處用 有時別人寫的不一定是對的,要查詢其他更權威的資料或查看原始碼 推薦參加IT鐵人賽,不管做的東西是難的還是簡單的,寫作的過程是在跟自己對話 技術文件舉例: - [Standard ECMA-262](https://www.ecma-international.org/publications/standards/Ecma-262.htm) (硬梆梆的官方文件) - [MDN web docs](https://developer.mozilla.org/zh-TW) (相對好讀,有範例)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully