Arki 的每日 BUG 观察
41 subscribers
78 photos
1 video
3 files
228 links
分享每天写的bug
以前端为主
Download Telegram
#js

safari 的 date 解析和 chrome 相比有很多种格式不支持

// safari
new Date('2000-04-12 00:00:00 GMT+0000')
// Invalid Date

// chrome
new Date('2000-04-12 00:00:00 GMT+0000')
Wed Apr 12 2000 00:00:00 GMT+0000


简单粗暴的解决方案
new Date('2000-04-12 00:00:00 GMT+0000'.replace(/-/g, '/'))


[Invalid date in safari
](https://stackoverflow.com/questions/4310953/invalid-date-in-safari)
#js

某位前辈在网络请求的 Promise 处理玩异常后直接 return 结束了函数,没有 reject 异常。。

结果就是这个 Promise 一直处于 pending 状态,无论使用 catch 还是 finally 都无法继续执行,及其坑爹。。
#js
判断一个变量是否是 object

我第一反应是用
typeof myObj === 'object'
但是 null 也是 object type
因此大部分场景还需要过滤 null

正确写法
typeof yourVariable === 'object' && yourVariable !== null
YSC 的频道
#WSL 中使用 npm 可能会遇到 syscall rename EACCESS 的问题,可以使用 wslunpindir 来解决。
这个问题我没遇到过,npm 更经常遇到的问题是 npm install -g 时的 EACCES permissions errors

几种解决方案官方已经写清楚了,可以自己查阅(嫌麻烦也可以直接 sudo 但是不推荐

Resolving EACCES permissions errors when installing packages globally
https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
#js #vue

vue 的 props 的 type checks 检查多种类型时必须使用数组的形式,不能使用`|`分隔
(写错既不会报错也没有提示
#js

window.open 弹窗
safari 为了防止网站骚扰用户,限制 window.open() 必须在用户点击的同一个事件循环内(event loop)(chrome 也有类似的策略但限制比较松),否则会被拦截

因此一些点击后需要先获取地址再跳转的场景(如支付需要先请求后端生成订单)在safari下就比较僵硬了

解决方案

比较简单的,可以引导用户允许弹出窗口,或者提前把异步操作做完

不过,今天的重点是找到的一个很酷的解决方案

https://stackoverflow.com/questions/20696041/window-openurl-blank-not-working-on-imac-safari
#js
写从 a - z 的循环时一定记得带上等号!!
又漏写了,吃了一个 WA。。
(我这里用 obj 偷懒了,用数组也是一个道理
#js
用于混淆代码的一个手段
利用 FunctiontoString 检测代码是否被格式化过

// 随便定义一个函数
const f = function() {
return true
}

---

console.log(f)
"function() {
return true
}"

压缩后的代码是没有换行的,利用这个特点可以判断代码是否(正在)被修改

思路来源
https://www.v2ex.com/t/597018
#js
chrome 不支持小于 12px 的 font-size,但是 safari 支持

BOOM!!!
Forwarded from Alex wang
#js
不愧是 js。。。
#js #vue

通过在写一个的vnode组件的方式简单地在 vue 实现渲染属性
<div>
<vnode :vnode="value"/>
</div>

{
components: {
Vnode: {
functional: true,
render: (h, ctx) => ctx.props.vnode
}
},
props: ['value']
}


https://stackoverflow.com/questions/49352525/can-you-render-vnodes-in-a-vue-template
#ts

styled-components 的 type 包 @types/styled-components 在 v.4.1.9 依赖了 @types/react-native ,导致全局类型冲突,结果就是使用了这个包的大部分项目 tsc 会打出 19 个类型冲突的错误

解决方案(都不太好

1. 降级使用 @types/styled-components@v4.1.8
2. tsconfig设置 types 手动指定类型目录

围观地址(半年了还没修QAQ
https://github.com/DefinitelyTyped/DefinitelyTyped/issues/33311