我需要使用我的代码进行一些快速测试(获取函数中某些变量的值),并且我想对它们进行全球化,因此我可以通过控制台访问它们.
我知道这个方法:
function foo() {
var foo = 'foo';
window.foo = foo; // Make foo global
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我有这样的事情怎么办:
function foo() {
var foo1 = 'foo';
var foo2 = 'foo';
var foo3 = 'foo';
var foo4 = 'foo';
var foo5 = 'foo';
var foo6 = 'foo';
var foo7 = 'foo';
var foo8 = 'foo';
}
Run Code Online (Sandbox Code Playgroud)
什么是全球化所有这些变量更快的方式,足不出户window.foo1 = foo1,window.foo2 = foo2等等?
我不希望这是一个代码高尔夫问题,只是一个普通的编程问题.
从这个javascript问题我学会了如何在谷歌浏览器中使用桌面通知,并决定在我的网站上实现这一点.
所以,每当某件事发生时,我都会做一个通知节目.
问题是,大多数情况下,用户打开了多个窗口,可以显示通知,从而导致重复通知.
有没有办法让我不会显示重复的谷歌浏览器通知?
谢谢.
The new redesign of Reddit features a really slick WYSIWYG/Markdown editor. Screenshots:
Once clicking on "Switch to markdown":
Is this an open-source library available for implementation, or is this entirely an internal Reddit-only solution?
On another note, I've been comparing a whole bunch of Markdown editors, and can't seem to find anything that works really well with React. SimpleMDE isn't bad, but its last commit was two and a half years ago, and it has no official React bindings either. …
我正在使用以下代码段在我的博客上显示方程式
<script src='http://www.mathjax.org/mathjax/MathJax.js' type='text/javascript'>
MathJax.Hub.Config({
extensions: ["tex2jax.js"],
jax: ["input/TeX","output/HTML-CSS"],
tex2jax: {inlineMath: [["$","$"],["\\(","\\)"]]}
});
</script>
Run Code Online (Sandbox Code Playgroud)
我想将方程式颜色改为白色,因为我的背景有点暗,怎么办呢?
我可以使用纯HTML执行此类操作,如果需要css和javascript:

当鼠标聚焦时,它会变成这样:

所以我在想一个图像占位符.我是在正确的轨道上,还是有更好/更简单或更直接的方法?
编辑:出于纯粹的好奇心,我将如何使用JavaScript实现这一点,因为所有当前的答案都与CSS有关?
例如,我想拆分这句话:
I am a sentence.
Run Code Online (Sandbox Code Playgroud)
分成5个部分; I,am,a,sentence,和..
我目前正在preg_split尝试使用explode,但我似乎找不到合适的东西.
这就是我尝试过的:
$sentence = explode(" ", $sentence);
/*
returns array(4) {
[0]=>
string(1) "I"
[1]=>
string(2) "am"
[2]=>
string(1) "a"
[3]=>
string(8) "sentence."
}
*/
Run Code Online (Sandbox Code Playgroud)
而且这个:
$sentence = preg_split("/[.?!\s]/", $sentence);
/*
returns array(5) {
[0]=>
string(1) "I"
[1]=>
string(2) "am"
[2]=>
string(1) "a"
[3]=>
string(8) "sentence"
[4]=>
string(0) ""
}
*/
Run Code Online (Sandbox Code Playgroud)
如何才能做到这一点?
如果我有以下内容:
<div id="flex">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
Run Code Online (Sandbox Code Playgroud)
假设flex-direction: row并且三个<div></div>元素适合一行,浏览器是否可以在每一行显示2行,两行,而不是在一行上显示3,然后在下一行显示1?
以下两个之间有什么实际区别吗?
button {
cursor: pointer;
}
Run Code Online (Sandbox Code Playgroud)
和:
button:hover {
cursor: pointer;
}
Run Code Online (Sandbox Code Playgroud)
MDN文档明确指出:
的
cursorCSS属性指定要显示的鼠标光标,当鼠标指针悬停的元素.
那么,有什么真正的区别吗?一个人应该优先于另一个,还是可以互换?
我正在尝试在 Windows 上设置 Docker 开发环境。我有一个像这样的代码目录结构:
project/
node-app/
react-app-1/
react-app-2/
shared/
Run Code Online (Sandbox Code Playgroud)
node-app,react-app-1并且react-app-2全部取决于 中的代码shared。所以,我正在考虑Dockerfile在每个应用程序中都有一个类似这样的内容:
FROM node:10.0
WORKDIR /app
COPY ../ .
WORKDIR /app/node-app
RUN npm install
Run Code Online (Sandbox Code Playgroud)
然而,这不起作用——Docker 给我一个错误,说它是一个Forbidden path outside the build context: ../.
解决这个问题的最佳方法是什么?我正在考虑在排序后设置某种 Docker Compose(再次用于本地开发),所以我的理想解决方案会记住这一点。
根据Google Chrome Developers YouTube 频道上发布的这段视频JSON.parse,实际上比对象文字更快。
我决定对此进行测试,我的结果一次又一次地非常支持对象文字。
请参阅此处:https ://jsperf.com/testing-obj-literal-vs-json-parse/1
另请参阅此处: https: //gist.github.com/lucaschen/ef0bb733f638563140b6bb0d374f3691(您可以在 Node.js 中运行它)
我的结果一致表明对象字面量解析比JSON.parse.
视频是否有误,或者我的测试是否不能公平地代表视频中概述的场景?
javascript ×5
css ×3
html ×3
node.js ×2
docker ×1
dockerfile ×1
flexbox ×1
json ×1
markdown ×1
npm ×1
performance ×1
php ×1
placeholder ×1
preg-split ×1
reactjs ×1
reddit ×1
regex ×1
string ×1
textbox ×1