我正在开发一个chrome扩展,我发现有重复无用的手动重新加载工作.
保存文件时,必须刷新chrome:\\extensions页面以允许浏览器重新加载扩展名.然后,您必须重新加载测试页以查看对文件的更改是否生效.
我是Chrome扩展开发的新手.有没有办法减少重复工作?我也很好奇Chrome扩展开发工作流程的最佳实践是什么.
英语不好,随意纠正.
当我尝试以无点样式编写JavaScript时,我发现如果你强制使用这种风格的每个函数,你有时会失去它的可读性.例如:
import R from 'ramda'
const ceil = Math.ceil
const pagination = {
total: 101,
itemsPerPage: 10,
currentPage: 1
}
// ================= Pointful style ==================
const pageCount = (pagination) => {
const pages = ceil(pagination.total / pagination.itemsPerPage)
const remainPages = pagination.total % pagination.itemsPerPage === 0 ? 0 : 1
return pages + remainPages
}
pageCount(pagination) // => 11
// ================ Pointfree style ==================
const getPages = R.pipe(
R.converge(R.divide, [R.prop('total'), R.prop('itemsPerPage')]),
ceil
)
const getRemainPages = R.ifElse(
R.pipe(
R.converge(R.modulo, [R.prop('total'), R.prop('itemsPerPage')]), …Run Code Online (Sandbox Code Playgroud) 我遇到了一个令我困惑的问题.我们都知道,具有相同来源的几个浏览器窗口(选项卡)可以共享JavaScript资源.
所以,我通过父窗口打开了一个子窗口window.open.子窗口通过父窗口调用全局函数window.opener.functionName.看看下面的两个片段:
parent.html
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Parent</h1>
</body>
<script type="text/javascript">
function sayHi(child) {
console.log("Before throwing an error..");
throw new Error('Some error');
}
window.open('child.html')
</script>
</html>
Run Code Online (Sandbox Code Playgroud)
child.html
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Child</h1>
</body>
<script type="text/javascript">
window.opener.sayHi(window);
</script>
</html>
Run Code Online (Sandbox Code Playgroud)
问题是:你可以console.log在parent.html窗口中找到结果,但在父窗口中抛出的异常会在child.html窗口中出现奇怪的现象.这让我感到困惑,因为BDD测试,我在父窗口中需要该异常.我怎样才能实现呢?
抱歉我的英语不好,随时纠正我的语法错误.
========================更新======================
我使用HTML5功能找到了这个问题的解决方案postMessage.但我仍然好奇为什么会这样.什么使异常从父窗口转移到子窗口?任何灵感都表示赞赏.