小编rob*_*obC的帖子

gitk只显示指定的分支

我想使用gitk比较2个分支,而不是其他分支历史的混乱.
我可以通过gui实现这一点:查看>新视图>分支和标签:v0.8.x v0.9.x
我尝试了以下内容,但它仍然显示所有分支:gitk --branches v0.8.x v0.9.x
正确的语法是什么?

git gitk

13
推荐指数
1
解决办法
1万
查看次数

从自执行函数返回函数的Javascript性能是什么?

在Firefox中,以下两个函数之间似乎存在很大的性能差异:

var n1 = 12;

var add1 = function(n2){
    return n1 + n2;
}

var add2 = (function(){
    return function(n2){
            return n1 + n2;
    }
})();
Run Code Online (Sandbox Code Playgroud)

我认为这必须归结于另一个范围的引入,因此创建了第三个示例,其中变量缓存了一个级别.但这显示出更大的减少(80%!)

var add3 = (function(){
    var cn1 = n1;
    return function(n2){
            return cn1 + n2;
    }
})();
Run Code Online (Sandbox Code Playgroud)

我本以为这里的关闭将缩小性能差距,而不是扩大它.有没有人知道这里发生了什么?

jsPerf测试页:http://jsperf.com/variable-scope-speed

javascript performance scope

11
推荐指数
1
解决办法
882
查看次数

未定义参数的性能损失

我经常在函数中有可选的参数,但是一些测试在firefox和safari中显示出巨大的性能影响(70-95%).奇怪的是,如果我传入未定义的文字值,那么就没有惩罚.这可能发生什么?我不会认为它是一个范围链问题,因为它们本身就是函数的本地.我是否开始将undefined传递给每个可选参数?

jsPerf:http://jsperf.com/function-undefined-args/2

javascript performance arguments

10
推荐指数
1
解决办法
479
查看次数

删除HTML脚本标记是否会对其包含的JavaScript产生任何影响?

从我的测试中可以看出,可以从DOM中删除脚本标记,而不会对其包含的JavaScript产生任何影响.
此测试通过执行部分破坏脚本DOM节点.即使这对脚本没有影响,count也会在从DOM中删除脚本标记1 为变量分配值.

<!DOCTYPE html>
<html lang="en">
<head>
<title> Test </title>

<script id="jQueryScriptTag" src="https://code.jquery.com/jquery-1.11.2.min.js"></script>

</head>
<body>

<button id="testBtn">Click to test</button>

<div id="output"></div>

<script id="testCodeScriptTag">
    var count;

    $("#jQueryScriptTag").remove();
    $("#testCodeScriptTag").remove();
    $("#output").append(
        "<p>jQueryScriptTag is " + document.getElementById("jQueryScriptTag") + "</p>" +
        "<p>testCodeScriptTag is " + document.getElementById("testCodeScriptTag") + "</p>" +
        "<p>count is " + count + "</p>"
    );

    count = 1;

    $("#testBtn").click(function(){
        $("#output").append(
            "<p>count is " + (count++) + "</p>"
        );
    });

</script>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

用例是从主机站点安全地删除注入的第三方脚本元素.

html javascript dom

9
推荐指数
1
解决办法
1160
查看次数

jQuery offset()被正文位置所打破:相对与元素边距相结合

这不是一个错误,因为Win7上的FF,Chrome,IE9和Safari的行为是一致的.

我正在处理的应用程序是主机页面的第三方,因此CSS是不可变的.脚本尝试将新div与现有元素对齐.

  • 身体是位置:相对的
  • 页面顶部有一个H1
  • 来自H1的边距似乎改变了身体0,0的计算位置 - 即使身体上的背景一直延伸到边缘,它的offsetTop属性报告0
  • 在身体上设置边框可以解决问题 - 看起来很奇怪但是在浏览器中是一致的吗?(不是可行的解决方案)
  • 删除H1边距可以解决问题(不是一个可行的解决方案)

这里的示例,JS被评论为复制每个案例:http:
//codepen.io/anon/pen/EGvlb

我不认为这是jQuery的错误 - 它似乎归结为H1边缘和body元素之间的合法关系?

$(function(){

  /* Setting body to position:relative breaks offset()
     because H1 margin moves body down */
  $(document.body).css({position: "relative"});

  /* Strange: putting a border on body fixes things? */
  //$(document.body).css({border: "1px solid #000"});

  /* Removing H1 margin removes problem */
  //$("h1").css({margin: 0});

  $("#overlay").css({
      left: $("#existing").offset().left,
      top: $("#existing").offset().top
  })
});
Run Code Online (Sandbox Code Playgroud)

javascript css jquery position

6
推荐指数
1
解决办法
3280
查看次数

Understanding type variables in type annotations

The Elm docs illustrate type variables like this:

> List.reverse
<function> : List a -> List a
Run Code Online (Sandbox Code Playgroud)

...the type variable a can vary depending on how List.reverse is used. But in this case, we have an a in the argument and in the result. This means that if you give a List Int you must get a List Int as well.

The docs for Maybe.map show this annotation:

map : (a -> b) -> Maybe a -> Maybe b
Run Code Online (Sandbox Code Playgroud)

那么为什么这些类型被注释为 …

types type-variables parametric-polymorphism elm

3
推荐指数
1
解决办法
64
查看次数

TypeScript allows a property to be set but not accessed (index signature)

This interface is an example from the TypeScript docs.
The compiler shows an error for height, even though it allows me to set it?

// Interface taken from https://www.typescriptlang.org/docs/handbook/interfaces.html
interface SquareConfig {
    color?: string;
    width?: number;
    [propName: string]: any;
}

const sq = <SquareConfig>{
    color: 'red',
    width: 7890,
    height: 888
}

console.log(sq.height); // Property 'height' does not exist on type 'SquareConfig'
Run Code Online (Sandbox Code Playgroud)

typescript

0
推荐指数
1
解决办法
675
查看次数

当行以冒号结束时,Javascript不会抛出"未定义"错误

我在JS函数中发现了这个错误,其中一个url是一个注释,但斜杠被省略了......奇怪的是没有抛出JS错误?为什么以冒号结尾的行不会产生... is not defined错误?

function test() {
    https://www.test.com
    console.log('success');
}
test();
Run Code Online (Sandbox Code Playgroud)

javascript

0
推荐指数
1
解决办法
71
查看次数