git diff认为没有变化..即使git status报告他们被修改了?
$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: file-added
modified: file-with-changes << it knows there are changes
Run Code Online (Sandbox Code Playgroud)
但为了看到差异,我需要显式添加最后一个reversion哈希..
$ git diff
(nothing)
$ git diff rev-hash
diff --git a/file-with-changes b/file-with-changes
index d251979..a5fff1c 100644
--- a/file-with-changes
+++ b/file-with-changes
.
..
Run Code Online (Sandbox Code Playgroud) 我无法理解为什么这甚至编译.我试过不同的格式,它们似乎都工作..
为什么有一个合法的enum of enum of enum of..?
interface I {
enum E implements I {
VAL;
}
class Test {
I.E f1 = I.E.VAL;
I.E.E f2 = I.E.VAL;
I.E.E.E f3 = I.E.VAL;
I.E.E.E.E.E f4 = I.E.VAL;
I.E v1 = I.E.VAL;
I.E v2 = I.E.E.VAL;
I.E v3 = I.E.E.E.E.E.E.VAL;
I.E v4 = I.E.E.E.E.E.E.E.E.E.E.VAL;
}
}
Run Code Online (Sandbox Code Playgroud)
我的IDE报告它编译得很好,虽然I.E.E对我来说没有意义.
这个剪辑将在nodejs和浏览器上没有任何抱怨的情况下运行:
this.return = function ( x ) {
return x
};
console.log ( this.return(1) );
Run Code Online (Sandbox Code Playgroud)
我期待它因语法错误而难以理解.
我的意思是,我能理解为什么this['return']有效......但我总是这return是一个词法分析器?
javascript是一种上下文敏感的语言?
补充说:重点是词法分析器没有T_RETURN标记,但它使用了一些T_STRING.是不是?
在nodejs REPL上,我试图清理一个定义为的数组,const array = [...] 并且发现使用array.forEach(() => /pop|shift/())不起作用.在这样的表达式之后,数组仍将保留其中的值.
我很清楚更好的清理阵列的方法,比如array.splice(0),但我对这种行为很好奇,似乎反直觉,至少对我而言.
const a = [1, 2, 3]
a.forEach(() => {
a.shift()
})
console.log(a) // [ 3 ]
const b = [1, 2, 3]
b.forEach(() => {
b.pop()
})
console.log(b) // prints [ 1 ]Run Code Online (Sandbox Code Playgroud)
起初我正在使用arr.forEach(() => arr.pop()),所以我虽然其中一个值是短路forEach但是将lambda包裹在一个体块中{ .. }也会产生相同的结果.
结果在不同的节点版本和浏览器中是一致的.所以它似乎是明确定义的行为.
剩余值的数量,仍在结果数组中的值,根据输入数组的长度而变化,似乎是 Math.floor(array.length / 2)
剩余的值总是根据使用的/pop|shift/方法排序,因此一些调用实际上是在改变输入数组.
它也通过调用返回相同的结果 Array.prototype.forEach(array, fn)