GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - tri613/JavaScript30: 30 Day Vanilla JS Challenge

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

107 Commits
107 Commits

Folders and files

NameName
Last commit message
Last commit date
01 - JavaScript Drum Kit
01 - JavaScript Drum Kit
 
 
02 - JS + CSS Clock
02 - JS + CSS Clock
 
 
03 - CSS Variables
03 - CSS Variables
 
 
04 - Array Cardio Day 1
04 - Array Cardio Day 1
 
 
05 - Flex Panel Gallery
05 - Flex Panel Gallery
 
 
06 - Type Ahead
06 - Type Ahead
 
 
07 - Array Cardio Day 2
07 - Array Cardio Day 2
 
 
08 - Fun with HTML5 Canvas
08 - Fun with HTML5 Canvas
 
 
09 - Dev Tools Domination
09 - Dev Tools Domination
 
 
10 - Hold Shift and Check Checkboxes
10 - Hold Shift and Check Checkboxes
 
 
11 - Custom Video Player
11 - Custom Video Player
 
 
12 - Key Sequence Detection
12 - Key Sequence Detection
 
 
13 - Slide in on Scroll
13 - Slide in on Scroll
 
 
14 - JavaScript References VS Copying
14 - JavaScript References VS Copying
 
 
15 - LocalStorage
15 - LocalStorage
 
 
16 - Mouse Move Shadow
16 - Mouse Move Shadow
 
 
17 - Sort Without Articles
17 - Sort Without Articles
 
 
18 - Adding Up Times with Reduce
18 - Adding Up Times with Reduce
 
 
19 - Webcam Fun
19 - Webcam Fun
 
 
20 - Speech Detection
20 - Speech Detection
 
 
21 - Geolocation
21 - Geolocation
 
 
22 - Follow Along Link Highlighter
22 - Follow Along Link Highlighter
 
 
23 - Speech Synthesis
23 - Speech Synthesis
 
 
24 - Sticky Nav
24 - Sticky Nav
 
 
25 - Event Capture, Propagation, Bubbling and Once
25 - Event Capture, Propagation, Bubbling and Once
 
 
26 - Stripe Follow Along Nav
26 - Stripe Follow Along Nav
 
 
27 - Click and Drag
27 - Click and Drag
 
 
28 - Video Speed Controller
28 - Video Speed Controller
 
 
29 - Countdown Timer
29 - Countdown Timer
 
 
30 - Whack A Mole
30 - Whack A Mole
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 
readme-base.md
readme-base.md
 
 

Repository files navigation

JavaScript30

30 Day Vanilla JS Challenge

Logs

記錄是為了逼自己天天寫。(?

  • Day1 -- 我有寫但放在別台電腦沒commit哈哈

  • Day2 -- 2016/12/13 complete!

  • Day3 -- 2016/12/15 用 css variable 這招倒是完全沒想到 (跟它壓根兒不熟),相比之下我整個大輸XD。 偷偷筆記起來。不過就是瀏覽器支援度還很差,近期可能還無法在production環境中使用吧……

  • Day4 -- 2016/12/21 不小心偷懶好久(爆) 這篇剛好可以趁機回憶一下前陣子看的教學影片!(講師超有趣XD)

  • Day5 -- 2016/12/26 寫是寫完了不過要來好好認真看一下flex才行QQ

  • Day6 -- 2017/01/03 年末總是在忙著慶祝嘛!(爆)

    • fetch
    • regular expression
  • Day7 + 8 -- 2017/01/04

  • Day9 + 10 -- 2017/01/05

    • console.time(name) + console.timeEnd(name)
    • console.group(name) + console.groupEnd(name)
    • Holding down the Shiftkey could be captured by MouseEvents and KeyboardEvents with event.shiftKey (true for "is holding down shift key")
  • Day11 + 12 -- 2017/01/06

  • Day13 -- PASS (欸)

  • Day14 -- 2017/01/20

    • 這章好重要,前陣子也有認真看了一下JS裡面by value跟by reference的問題,另外開一個區塊寫XD
  • Day15 -- 2017/01/28 (新年寫code...廠廠)

    • JSON.parse(null)是OK的,但JSON.parse(undefined)就會跳error。
  • Day16 -- 2017/01/28

    • 如果在捕捉滑鼠移動位置事件時,假如被掛上listener的元素裡面還有子元素的話, 記得要另外加上子元素和父元素的相對位置。
     let x = e.target.offsetX;
     let y = e.target.offsetY;
     if (this !== e.target) {
     	x = x + e.target.offsetLeft;
     	y = y + e.target.offsetTop;
     }

    延伸:圖解offsetLeft、offsetTop、offsetWidth和offsetHeight

Notes

Day14 - JavaScript References VS Copying

記得在stackoverflow上面也有人提出其實JS沒有分所謂的by value和by reference, 而是以變數的值是否immutable的差別來區分, 不過我覺得這樣子的分法對我來說比較好理解。

  1. By Value (Copying)

一般來說只要是 strings, numbers 和 booleans,都可以說是 by value。

let a = "string";
let b = a;
console.log(a, b); // "string", "string"
b = "another string";
console.log(a, b); // "string", "another string"
  1. By Reference

如果是 array 或者 object,則會以 by reference 的方式傳遞。

let person1 = {
	name: "Trina",
	age: 100,
	gender: "female"
};
let person2 = person1;

console.log(person1, person2);
//Object {name: "Trina", age: 100, gender: "female"}, Object {name: "Trina", age: 100, gender: "female"}

person2.name = "Sherry";
console.log(person2.name); //"Sherry"
console.log(person1.name); //"Sherry" --> person1 has been changed too!

Array 也是一樣的道理:

let players = ["Trina", "Sherry", "Pisuke", "Kuma"];
let team = players;
console.log(players, team);
// ["Trina", "Sherry", "Pisuke", "Kuma"],
// ["Trina", "Sherry", "Pisuke", "Kuma"]

team[3] = "Usagi";
console.log(players);
// ["Trina", "Sherry", "Pisuke", "Usagi"] --> players has been changed too!

要解決這個問題,就必須把Object或Array直接Copy一份才行。

  • Copying an array

     //以下幾種方式皆可行
     const teamCopy1 = players.slice();
     const teamCopy2 = [].concat(players);
     const teamCopy3 = [...players]; //es6
     const teamCopy4 = Array.from(players);
  • Copying an object

     const personCopy = Object.assign({}, person, {
     	newProperty: "some additional property for personCopy"
     });

    要注意的是以上的方法是 Shallow copy,如果 Object 本身是二維以上的話,使用上面的方式還是會有 By reference的情況發生。

     let me = {
     	name: "Trina",
     	age: 24,
     	social: {
     		twitter: "@tri613",
     		github: "tri613"
     	}
     };
    
     let me2 = Object.assign({}, me);
     me2.social.twitter = "@nomoney";
    
     console.log(me.social);
     //{twitter: "@nomoney", github: "tri613"} --> Changed!

    這種情況需要靠Deep clone來解決,最簡單 (但效率表現沒那麼好) 的方式 是直接使用JSON格式encode再decode的方式解決。

     const meCopy = JSON.parse(JSON.stringify(me));

    其他的方式可以參考stackoverflow上面的這篇。

About

30 Day Vanilla JS Challenge

Resources

Readme
Activity

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.