Giter Site home page Giter Site logo

studynote's People

Contributors

hanjc1993 avatar

Watchers

James Cloos avatar

studynote's Issues

函数节流 和 防抖

概念问题,都很简单
节流:延迟一段时间才放开,一般用于高发事件比如鼠标滑动、页面滚动等
let cantUse = false
someEvent(()=>{
if(cantUse) return
//do something
cantUse = true
setTimeout(()=>{
cantUse = false
},200)
})

防抖:每次事件触发后先清空上一个延迟函数并启动下一个延迟函数,最终执行的内容放在延迟函数中
let timeOut = null
someEvent(()=>{
clearTimeout(timeOut)
timeOut = setTimeout(()=>{
//do something
},200)

interval经验

let baseStep = this.baseStep;
if (baseStep == -1) {
return dsbridge.toast('获取步数失败,请重试!本次不扣参与次数');
}
console.log('开始轮询:' + baseStep);
let stopCnt = -2, // 开始游戏后,停止运动了多少个interval。
// 刚开始的话,多2s等待时间,体验更友好。缺点是如果一步也没跑的话,5s才能自动结束
// 3s不动就自动结束游戏
interval = setInterval(() => {
if (stopCnt < 4) {
// 正常不会超过3,否则说明轮询已结束,这个判断主要处理如下情况:
// 在清除定时器的瞬间,其实有最后一次已经开始倒计时,只不过还没执行,这次执行不会被终止,下次执行才会被终止。这导致stopRun可能被连续调用两次
dsbridge.getStep(step => {
// console.log('获取到的步数:' + step);
let newStep = step - baseStep;
console.log('显示的步数:' + newStep);
if (newStep == this.step) {
if (stopCnt == 3) {
stopCnt = 99;
clearInterval(interval);
this.stopRun();
} else {
stopCnt++;
}
} else {
stopCnt = 0; // 动了就重置
this.step = newStep;
// 极限20分钟,如果每分钟250步,就是5000步
if (newStep >= 5000) {
stopCnt = 99;
clearInterval(interval);
this.stopRun();
dsbridge.toast('超出步数上限!自动结束游戏');
}
}
});
}
}, 1000);

12月19日

1、理解别人代码时候,先整清楚业务逻辑,然后查看页面dom,再点击页面观察数据变化,最后才看代码
2、vue的$nextick(cb),是在赋值之后立刻调用,视图更新之后回调,适用于数据量很大的渲染

学习

1、小程序wxml中不能使用变量作为属性名,下面这个是不合法的
{{hehe[item.shuxing]}}
2、

html5 history pushState和replaceState的使用

html5 history pushState和replaceState的使用

pushState和replaceState是一个HTML5的新接口,他们的作用非常大,可以做到改变网址却不需要刷新页面,这个特性后来用到了单页面应用中比如:vue-router,react-router-dom里面,咱们就先看看它的原理和使用案例吧。

pushState方法接受三个参数,依次为:

  1. state:一个与指定网址相关的状态对象,popstate事件触发时,该对象会传入回调函数。如果不需要这个对象,此处可以填null。
  2. title:新页面的标题,但是所有浏览器目前都忽略这个值,因此这里可以填null。
  3. url:新的网址,必须与当前页面处在同一个域。浏览器的地址栏将显示这个网址。

最常用的方法:window.history.pushState(null,null,'download?id=1');
完整使用:var oState= {title: '下载' };window.history.pushState(oState, '下载', 'download?id=1');
特点:pushState()可以创建历史,可以配合popstate事件,可以使用history.go(-1)返回到上一个页面。比如:window.addEventListener('popstate', function(evt){var state = evt.state;document.title= state.title; }, false);

replaceState和pushState原理一样使用也一样:

最常用的方法:window.history.replaceState(null,null,'download?id=1');
完整使用:var oState= {title: '下载' };window.history.replaceState(oState, '下载', 'download?id=1');
特点:replaceState不会加入到历史记录里面,用history.go(-1)会跳过当前页面相当于是history.go(-2)。

将vscode添加到右键菜单

原文来自:https://www.jianshu.com/p/b49002fa10a7

以下在原文基础上进行修改

利用注册表在右键添加Visual Studio Code的快捷方式

VSCode安装过程中忘了勾选添加到右键菜单的选项,或者重装vscode导致之前的配置失效,可采取以下办法解决

关联文件

Win+R 打开运行,输入regedit,打开注册表,找到HKEY_CLASSES_ROOT*\shell分支,如果没有shell分支,则在*下点击右键,选择“新建-项”,建立shell分支。

在shell下新建“VisualCode”项,在右侧窗口的“默认”键值栏内输入“open with visual code”,这是单击鼠标右键时VisualCode启动程序的显示值。项的名称和键值可以任意,以含义明确为好。其中键值将显示在右键菜单中。

在“VisualCode”下再新建Command项,在右侧窗口的“默认”键值栏内输入记事本程序所在的路径,我的是:"D:\Program Files (x86)\Microsoft VS Code\code.exe" "%1"。其中的%1表示要打开的文件参数。也就是Visual Code启动程序,找不到的话就在开始里面查找Visual Studio Code,再右键打开文件位置

关闭注册表,即可生效。

关联文件夹

以上方法可以在选中文件时右键在菜单栏中显示:"open with visual code",但当右键文件夹时仍然不能显示此选项,所以还要进行下面的操作:

打开注册表,找到HKEY_CLASSES_ROOT\Directory\shell和HKEY_CLASSES_ROOT\Directory\background\shell,按照上面2、3的方法添加即可。

添加Icon

在原有的项上新建可扩充字符串值,命名为Icon,像一个键值对那样把D:\Program Files (x86)\Microsoft VS Code\code.exe放进去就可以了。

删除

当更新程序或者是卸载Visual code时直接找到注册表中的相应位置修改或删除即可。

顺便说一下360安全卫士的右键绑定删除:找到“HKEY_CLASSES_ROOT*\shellex\ContextMenuHandlers”;如果是只对文件夹有效的项目,则存放在
“HKEY_CLASSES_ROOT\Directory\shell”
“HKEY_CLASSES_ROOT\Directory\shellex\ContextMenuHandlers”
“HKEY_CLASSES_ROOT\Folder\shell”
“HKEY_CLASSES_ROOT\Folder\shellex\ContextMenuHandlers”
找到后将他们删除即可。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.