有人可以解释一下这个摘录单页面深度应用程序的含义吗?
类的常见模式(例如,从原型实例化的对象)是通过使用下划线将类方法标记为私有来简单地将它们标记为私有.您可以通过使用.call/.apply来设置"this"来正确隐藏类方法,但我不会在此处显示它; 这是一个小细节.
我认为有一种方法可以实际上使"私有"JavaScript方法实际上无法访问,而不是仅使用下划线标记它们的惯例,但我无法想象实现的样子,以及如何使用它.
这不起作用:
li[depth="3"] { padding-left: calc(40px * attr(depth integer)); }
Run Code Online (Sandbox Code Playgroud)
但是,这有效:
li[depth="3"] { padding-left: calc(40px * 3); }
Run Code Online (Sandbox Code Playgroud)
显然attr(name type)内部calc()尚不支持......
有没有办法用CSS替换下面的CSS,适用于属性的所有整数值depth?
li[depth="2"] { padding-left: 40px; }
li[depth="3"] { padding-left: 80px; }
li[depth="4"] { padding-left: 120px; }
Run Code Online (Sandbox Code Playgroud) sed表达式G; s/\n/&&/; /^\([ ~-]*\n\).*\n\1/d; s/\n//; h; P是什么:做什么?究竟它匹配什么,它是如何匹配的?
这是从todo.sh.在上下文中:
archive()
{
#defragment blank lines
sed -i.bak -e '/./!d' "$TODO_FILE" ## delete all empty lines
[ $TODOTXT_VERBOSE -gt 0 ] && grep "^x " "$TODO_FILE" ## if verbose mode print completed tasks..
grep "^x " "$TODO_FILE" >> "$DONE_FILE" ## append completed tasks to $DONE_FILE
sed -i.bak '/^x /d' "$TODO_FILE" ## delete completed tasks
cp "$TODO_FILE" "$TMP_FILE"
sed -n 'G; s/\n/&&/; /^\([ ~-]*\n\).*\n\1/d; s/\n//; h; P' "$TMP_FILE" > …Run Code Online (Sandbox Code Playgroud) 我只是通过改成import * as CodeMirror普通而解决了一个错误import CodeMirror。
import * as CodeMirror一直起作用,直到因其副作用而导入插件为止:预期的新fold属性未定义。问题:(我试图了解发生了什么更好的事情)
default属性添加到CodeMirror?(或更可能的是:将模块包装在看起来非常相似的另一个对象内)最可能的怀疑者:
更多细节:
此代码无法正常工作:
import * as CodeMirror from 'codemirror'
import 'codemirror/addon/fold/indent-fold.js' # should add `fold` object to `CodeMirror`
console.log typeof CodeMirror ## 'object'
console.log typeof CodeMirror.fold ## 'undefined'
console.log typeof CodeMirror.default ## 'function'
## Work-around:
console.log typeof CodeMirror.default.fold ## 'object'
Run Code Online (Sandbox Code Playgroud)
此代码按预期工作:
import CodeMirror from 'codemirror'
import 'codemirror/addon/fold/indent-fold.js' # should add …Run Code Online (Sandbox Code Playgroud) 我有以下函数。代码执行了我需要它执行的操作,但是由于声明的原因,其结构不正确,因此它给出了“(ESLint) 将函数移动到主体根”错误:
这是我的代码:
function onSuccess(result) {
if (result) {
function GetTotal(result) {
var totBal = 0;
var str = 'R';
for (var i = 0; i < result.length; i++) {
totBal += result[i].Price;
}
str += totBal.toFixed(2);
return str;
}
var span = document.getElementById("Total");
span.innerHTML = GetTotal(result);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的:
function onSuccess(result) {
var fn;
if (result) {
fn=function GetTotal(result) {
var totBal = 0;
var str = 'R';
for (var i = 0; i < result.length; i++) {
totBal …Run Code Online (Sandbox Code Playgroud) void element.offsetWidth;是一行奇怪的代码,它似乎什么都不做,但却是 CSS 动画工作所必需的。这条线有什么作用,为什么需要它?
如果整行都被注释掉,动画只发生一次但不会重复。(如果void删除它仍然有效。)
将完整的代码/演示是住在这里; 我试图复制下面的相关摘录:
脚本.js:
beatIndicator = document.getElementById("beatIndicator"),
...
// Happens every time a beat starts:
beatIndicator.classList.remove("anim");
void beatIndicator.offsetWidth; // Why is this line needed?
beatIndicator.classList.add("anim");
Run Code Online (Sandbox Code Playgroud)
示例-advanced.html
<span style="display: none;" id="beatIndicator" class="pulse"></span>
<style>
.pulse {
width: 40px;
height: 40px;
border-radius: 50%;
background: #f44336;
z-index: 3;
left: -18px;
display: inline-block;
vertical-align: middle;
margin-left: 10px;
}
@keyframes pulse-anim {
from {
box-shadow: rgba(244, 67, 54, 1) 0px 0px 0px 0px;
}
to {
box-shadow: …Run Code Online (Sandbox Code Playgroud) 我每小时都会向模式添加条目,以便跟踪当天的增长情况,同时保持当前的当前分数.现在我希望能够提取过去一周每天的最新记录.结果将是6个记录,在午夜或午夜左右,前6天,第7个记录是当天的最新记录.
这是我的架构:
var schema = new Schema({
aid: { type: Number }
, name: { type: String }
, score: { type: Number }
, createdAt: { type: Date, default: Date.now() }
})
Run Code Online (Sandbox Code Playgroud)
编辑
我已经尝试过使用这个静态,但它会将完全相同的记录拉7次
schema.statics.getLastWeek = function(name, fn) {
var oneday = 60 * 60 * 24
, now = Date.now()
, docs = []
for (var i = 1; i <= 7; i++) {
this.where('name', new RegExp(name, 'i'))
.where('createdAt')
.gte(now - (i * oneday))
.desc('createdAt')
.findOne(function(err,doc){
docs.push(doc)
}) …Run Code Online (Sandbox Code Playgroud) 例如来自文档的这个:
<canvas
width={32}
height={32}
></canvas>
Run Code Online (Sandbox Code Playgroud)
花括号在这里有什么作用?