WIP: BugFix407 + Refactor #41
Draft
jinhaolin
wants to merge 6 commits from
Bug407-JinHaoLin
into Alpha-snapshot20240618
pull from: Bug407-JinHaoLin
merge into: mrlan:Alpha-snapshot20240618
mrlan:Alpha-snapshot20240618
mrlan:Bug580-Hui
mrlan:Bug565-Hui
mrlan:Bug394-Hui
mrlan:Bug478-Hui
mrlan:Bug501-Hui
mrlan:Bug511-Hui
mrlan:Bug518-Hui
mrlan:Bug563-Hui
mrlan:bug555-fangchen
mrlan:Bug547-FanWenQi-Adapted
mrlan:SPM2023S-QianJunQi
mrlan:Bug536-Jiangwangzhe
mrlan:Bug540-XiongJiaming
mrlan:Bug579-LuKangyang
mrlan:BUG543-JiWenkai
mrlan:Bug574-ChenLingjie2
mrlan:Bug573-PanBinjie
mrlan:Bug570_CaiShuHuang
mrlan:Bug578-ChenChen2
mrlan:Bug578-ChenChen
mrlan:Bug577-JiangXueQin
mrlan:Bug576-XiaBaizhi
mrlan:Bug564-JiangChao
mrlan:Bug572-ZhongYi2
mrlan:Bug533-ZhangXuDong
mrlan:Bug392-LiJie
mrlan:Bug358-LiJie
mrlan:Bug534-WangWeitao
mrlan:Bug569-YuTianshuai
mrlan:Bug563-HuangHaoqi
mrlan:Bug571-TongQi
mrlan:Bug572-ZhongYi
mrlan:Bug566-SunJiawen
mrlan:Bug574-ChenLingjie
mrlan:Bug565-ChenYuhang
mrlan:Bug568-SongHaiyan
mrlan:Bug567-YuZheChen
mrlan:Bug571-TonQi
mrlan:Bug561-LiangZiyue
mrlan:Bug511-Bosh
mrlan:Bug555-chenshiying
mrlan:Bug513-Mayada
mrlan:Bug543-AyaOK
mrlan:Bug518-Mponeja
mrlan:Bug543-Aya
mrlan:Bug547_FanWenQi
mrlan:bug-497Gongzhengcheng
mrlan:Bug500-Badr
mrlan:Bug518-Esther
mrlan:Bug536-QianLetao
mrlan:Alpha-snapshot20230621
mrlan:Bug533-Yuyikai
mrlan:Bug562-Wuyichen
mrlan:Alpha-snapshot20230621OK
mrlan:Bug476-LiMengdie
mrlan:Bug545-HuangHuiLing
mrlan:Bug561-WanZiKun
mrlan:BugTBD-LiSinan
mrlan:master
mrlan:Bug579
mrlan:0618、
mrlan:Bug551-DingZeYu
mrlan:547
mrlan:542
mrlan:Bug528-TangJiao
mrlan:Bug553_LinShan
mrlan:Bug-561
mrlan:fix-vuln
mrlan:Bug476-Yuhuangtao
mrlan:Bug527-ZhouZhifang
mrlan:Alpha-snapshot20230615
mrlan:Bug473-Buya
mrlan:Bug534-NingShushuang
mrlan:improvment_GuHan
mrlan:Bug393-TanYanMei
mrlan:improvment-NiWeiCong2
mrlan:refactor-huangzirui
mrlan:Bosh
mrlan:Alpha-snapshot20230605
mrlan:refactor-wangyu
mrlan:Alpha-snapshot20230601
mrlan:Alpha-snapshot20230531
mrlan:Bug529-GuHan
mrlan:Bug492-XuHongJian-HuangZirui
mrlan:Alpha-snapshot20230529
mrlan:Refactor_qianjunqi
mrlan:Bug522-HuangZirui
mrlan:Refactor-XunYucan
mrlan:Alpha-snapshot20230525
mrlan:Refactor-HeZhengzheng
mrlan:Alpha-snapshot20230511
mrlan:Alpha-snapshot20230519
mrlan:Bug476-YuHuangtao
mrlan:Bug476-ZhangWeiHao-YuHuangtao
mrlan:Bug473-LuXiaochen
mrlan:Bug493-GongKeCheng
mrlan:Bug488-TangWei
mrlan:SOFTARCH2023S-ZENOVIO
mrlan:Bug532-HuangDan
mrlan:Bug476-ZhangWeiHao-BaoYuelin
mrlan:Bug504-LiJia
mrlan:SPM2023-PR44-YuGaoxiang
mrlan:Bug476-ZhangWeiHao
mrlan:Alpha-snapshot20230507
mrlan:Huangdan
mrlan:Bug509-XieQiuHan-WangZiming-HuangDan
mrlan:Alpha-snapshot20230506
mrlan:improvment-NiWeiCong
mrlan:Bug502-YuGaoXiang
mrlan:bug359-zhangkeli
mrlan:593
mrlan:Alpha-snapshot20230427
mrlan:Alpha-snapshot20230425
mrlan:Bug509-XieQiuHan-WangZiming
mrlan:Alpha-snapshot20230426
mrlan:Alpha
mrlan:Lanhui-update-README2
mrlan:SPM2022F-CONTRIBUTORS-WuWenZhuo
mrlan:Bug490-ChenQiuwei
mrlan:Bug525-Hui
mrlan:englishpal
mrlan:AAALF
mrlan:Bug509-XieQiuHan
mrlan:SPM2022F-CONTRIBUTORS-DingRui
mrlan:SPM2022F-CONTRIBUTORS-jiaojiao
mrlan:Bug521-LiYuFeng-refactor
mrlan:Bug492-XuHongJian
mrlan:SPM2022F-CONTRIBUTORS-XIEQIUHAN
mrlan:SPM2022F-CONTRIBUTORS-XuHongJian
mrlan:509
mrlan:Bug512-RenYu
mrlan:SPM2022F-CONTRIBUTORS-GONGKE
mrlan:Bug521-LiYuFeng
mrlan:SPM2022F-CONTRBUTORS-luofei
mrlan:SPM2022F-CONTRIBUTORS-RUANYUXUAN
mrlan:bug492
mrlan:SPM2022F-CONTRIBUTORS-LINJUNHONG
mrlan:SPM2022F-CONTRIBUTORS-TANGWEI
mrlan:Bug508-CenHaotian
mrlan:SPM2022F-CONTRIBUTORS-GONGKECHENG
mrlan:Bug499-Hui
mrlan:SPM2022F-CONTROIBUTORS-XUHONGJIAN
mrlan:SPM2022F-CONTRBUTORS-TECHLEADNAME
mrlan:Bug505-ZhangYiteng
mrlan:Bug495-LiangLiGang
mrlan:SPM2022F-CONTRIBUTORS-LIJIA
mrlan:SPM2022F-CONTRIBUTORS-CENHAOTIAN
mrlan:SPM2022F-CONTRIBUTORS-ChenQiuwei
mrlan:Bug499-WangZiming
mrlan:Bug487-WuYuhan-Refactor
mrlan:Hui-Build
mrlan:Bug487-WuYuhan
mrlan:Bug412-JiangLetian-Refactor
mrlan:Bug412-JiangLetian
mrlan:Hui-EscapeUserInput
mrlan:Bug422-XuXing
mrlan:Improvement-Stewart
mrlan:Bug400-QiuZhonghui-Refactor
mrlan:Bug477-ChenJingyi
mrlan:Bug400-QiuZhonghui
mrlan:Bug474-RenYinJie
mrlan:Bug344-JiangXueHong
mrlan:Bug428-LouJiCheng
mrlan:SOFTARCH2022S-ZAYID-478
mrlan:Bug392-LuoYu
mrlan:Bug358-TengJiaQian
mrlan:Bug410-DuanJiaJie
mrlan:Bug209-LiuChangYou
mrlan:Bug393-QinYanMei
mrlan:IMPROVE-WangWeiLong
mrlan:Bug391-LiuYiXiu
mrlan:Bug260-Mohanad
mrlan:bug209_yaaqobv2
mrlan:BugFix407-JinHaoLin
mrlan:Bug394-MiaoChenShuo
mrlan:bug209-yaaqob
mrlan:Bug257-MaJiaBin
mrlan:Bug395-Anxiuxiu
mrlan:Deployment
mrlan:ChenTianle-TypoCorrection
mrlan:Hui-SaferSQL
mrlan:BugFix347
mrlan:WangXuan-Highlight-Pronounce
mrlan:Lanhui-Selenium
mrlan:Lanhui-update-README
mrlan:BugFix300
mrlan:Lanhui-IncreaseChanceOfGettingDifficultArticles
mrlan:BugFix293
mrlan:BugFix284
mrlan:Lanhui-flash-messages
mrlan:Lanhui-go-bootstrap
mrlan:Lanhui-build.sh
mrlan:BugFix254-Author-ZhanJianhao
mrlan:Lanhui-add-articles
No reviewers
Labels
Clear labels
No items
No Label
Milestone
Clear milestone
No items
No Milestone
Projects
Clear projects
No project
Assignees
Clear assignees
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.
No due date set.
Dependencies
No dependencies set.
Reference: mrlan/EnglishPal#41
Reference in New Issue
There is no content yet.
Delete Branch "Bug407-JinHaoLin"
Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?
[BUGFIX] fillword.js: in function 'read', add cancel current reading before read new words. BugFix 407
Bug412-JiangLetian 不是我们的提交,请注意
Bug407-JinHaoLinto WIP: Bug407-JinHaoLinWIP: Bug407-JinHaoLinto WIP: BugFix407WIP: BugFix407to WIP: BugFix407 + Refactor[REFACTOR] fillword.js: Use const、let、var instead of use var singly. Add comments for understanding.
@ -21,2 +26,3 @@
//关闭正在读的单词
function onReadClick(){
isRead = !isRead;
let isRead = !isRead;
let 是块级作用域,在带有let的块中声明的变量仅可在该块中使用。这里我觉得去掉let更好,因为在fillingWord()中也用到了isRead。
@ -19,0 +20,4 @@
//关闭当前正在读的单词
reader.cancel()
//创建新的朗读任务
let msg = new SpeechSynthesisUtterance(word);
这里的let我觉得用得很好,限制了msg只在块级作用域起作用
@ -10,1 +8,3 @@
var word = getWord();
//填充字符
function fillingWord(){
let word = getWord();
这里将var改成let我觉得用得很好,使得变量
word
只在块级作用域起作用@ -5,0 +1,4 @@
var isRead = true;
var isChoose = true;
const reader = window.speechSynthesis; // 全局定义朗读者,以便朗读和暂停
//获取字符
注释规范:所有的注释部分"//"后面有且仅有一个空格。
@ -5,3 +5,2 @@
function getWord(){
var word = window.getSelection?window.getSelection():document.selection.createRange().text;
return word;
return window.getSelection?window.getSelection():document.selection.createRange().text;
这里将两行代码化简为一行,看起来不那么繁琐,少定义一个变量也减少出错的概率,但是格式上要注意空格 ?和:的前后都要有空格
在变量前添加var类型,常量前增加const,增强代码可读性
@ -4,1 +1,3 @@
var isRead = true;
var isChoose = true;
const reader = window.speechSynthesis; // 全局定义朗读者,以便朗读和暂停
在变量前添加var类型,常量前增加const,增强代码可读性
@ -11,3 +11,3 @@
if (isRead) read(word);
if (!isChoose) return;
var element = document.getElementById("selected-words");
let element = document.getElementById("selected-words");
将var替换为let,是最新的JavaScript语法
这里有评审错误,将var改为let的原因是:let是块作用域,所以在块作用域内定义的变量,比如说在for循环内,在其外面是不可被访问的,所以for循环推荐用let。将var改为let这点做的很好。
@ -19,0 +18,4 @@
//@word 要朗读的单词
function read(word){
//关闭当前正在读的单词
reader.cancel()
这里完善了read函数,在创建新的朗读时,将旧的或者正在进行的朗读任务取消。相比于修改之前的函数,修改后的函数让整个项目更加严谨。
@ -12,3 +12,3 @@
if (!isChoose) return;
var element = document.getElementById("selected-words");
let element = document.getElementById("selected-words");
element.value = element.value + " " + word;
我觉得这里的代码可以改为
element.value += " " + word;
可以减少重复代码,让整个程序看起来更加简洁,结构清晰。@ -19,0 +16,4 @@
document.getElementById("text-content").addEventListener("click", fillingWord, false);
//朗读单词
//@word 要朗读的单词
function read(word){
这里将s改为了word,代码增强可读性,能够快速明白word代表的含义是要朗读的单词。改的好
WIP: BugFix407 + Refactorto WIP: BugFix407 + RefactorStep 1:
From your project repository, check out a new branch and test the changes.Step 2:
Merge the changes and update on Gitea.