-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
重覆宣告參數等幾點 coding style 建議 #19
Comments
下次 commit 會修正,之前有想過要改,但是改完覺得看起來很不舒服就改回去了(?
差別在哪??
之前的習慣是暫存資料會用 snake_case, |
block 裡宣告就和 var 一樣, |
剛剛查了一下 function declare 會被限制在 block 裡面
foo('outside'); // TypeError: foo is not a function
{
function foo(location) {
console.log('foo is called ' + location);
}
foo('inside'); // works correctly and logs 'foo is called inside'
} [ref] |
原來改了 |
其實你們兩個都對一半 {
function foo(location) {
console.log('foo is called ' + location);
}
foo('inside'); // works correctly and logs 'foo is called inside'
}
foo('outside'); // It works! |
JavaScript 很棒吧 |
答案是看你有沒有 var hey
if (true) {
hey = function () {
}
} 你們自己試吧: "use strict" // 把這行刪掉就是非嚴格模試
console.log(typeof hey)
if (true) {
function hey() {
return hey
}
}
console.log(typeof hey) |
總之function會被限制在block中,符合該段程式的需求,無須修改,找時間把 Coding Style 整合之後再把這篇關掉 |
不要宣告和參數同名的變數
不要在 block 裡宣告函數
記得 block 裡不能宣告函數,只能用函數表達式。
和不能在 block 裡用 var 宣告變數差不多。
雖然沒什麼關係,但我會盡量避免。
為什麼要用
snake_case
?javascript 統一用 camelCase 好嗎?
在
playList
裡怎麼一堆song_list
song_data
?The text was updated successfully, but these errors were encountered: