git 强制覆盖本地文件

转载自:https://vimsky.com/article/3679.html

重要提示:如果您有任何本地更改,将会丢失。无论是否有--hard选项,任何未被推送的本地提交都将丢失。


git fetch --all // 从远程拉取最新文件,而不尝试合并或者rebase任何文件
git reset --hard origin/master // 将主分支重置为上一步所拉取的最新文件,--hard选项更改工作树中的所有文件以匹配origin/master中的文件

*:假如希望保留本地尚未提交的修改,推荐先从本地分支创建一个新的分支(git checkout newBranch)

火狐浏览器下隐藏滚动条

转载自:http://jsfiddle.net/bizamajig/md27H

原理:父元素overflow:hidden;子元素中width宽度比父元素宽,多出的宽度即浏览器滚动条的宽度

<div id=”content”>
<div id=”scrollable”></div>
</div>


#content {
position: relative;
width: 200px;
height: 200px;
border: 1px solid black;
overflow: hidden;
}
#scrollable {
height: 200px;
width: 218px;
overflow-y: scroll;
}

this指向?

this is set according to how the method is called, and not according to how the method is written. So for obj.method(), this will be set to obj inside of method(). For obj.method.call(x), this inside of method() will be set to x. It is determined by how it’s called. What that also means is that if you pass it as a callback to e.g. onclick, this will be set to the global window object rather than what you expect.

参考1:https://stackoverflow.com/questions/13224620/the-this-keyword-returns-the-window-object-within-an-objects-prototype-in-jav

参考2:https://segmentfault.com/a/1190000008400124

JavaScript 函数中的 this 指向并不是在函数定义的时候确定的,而是在调用的时候确定的。换句话说,函数的调用方式决定了 this 指向

继续阅读this指向?

微信分享地址传参时的问题

问题描述:当微信分享地址携带两个相同的参数时,请求地址中会携带两个参数,但是复制出来的地址却只携带了其中一个参数(导致定位问题失败)

附带替换参数值代码:

changeUrlKeyVal: function(key, val) {
  const href = location.href.split(“#”)[0];
  const pattern = key + ‘=([^&]*)’;
  const replaceText = key + ‘=’ + val;
  return href.match(pattern) ? href.replace(eval(‘/(‘ + key + ‘=)([^&]*)/gi’), replaceText) : (href.match(‘[\?]’) ?href + ‘&’ + replaceText : href + ‘?’ + replaceText);
}

注意!!!谨记!!!

 

npm报错:Unexpected end of JSON input while parsing near ‘…ze”:”0.4.0″},”devDepe’的解决方法

参考链接:https://github.com/npm/npm/issues/19072

错误描述:NPM安装依赖包时报错,Unexpected end of JSON input while parsing near ‘…ze”:”0.4.0″},”devDepe’

解决办法:npm cache clean –force