假设一个类有一个public int counter由多个线程访问的字段.这int只是递增或递减.
要增加此字段,应使用哪种方法,为什么?
lock(this.locker) this.counter++;,Interlocked.Increment(ref this.counter);,counter为public volatile.现在,我发现volatile,我已经删除了许多lock语句和使用Interlocked.但是有理由不这样做吗?
是否有任何JavaScript库使查询字符串中的字典成为ASP.NET样式?
可以使用的东西像:
var query = window.location.querystring["query"]?
Run Code Online (Sandbox Code Playgroud)
是"查询字符串"叫别的东西外面.NET的境界?为什么没有location.search分成键/值集合?
编辑:我已经编写了自己的函数,但是任何主要的JavaScript库都可以这样做吗?
鉴于此功能:
function Repeater(template) {
var repeater = {
markup: template,
replace: function(pattern, value) {
this.markup = this.markup.replace(pattern, value);
}
};
return repeater;
};
Run Code Online (Sandbox Code Playgroud)
如何this.markup.replace()全球更换?这是问题所在.如果我像这样使用它:
alert(new Repeater("$TEST_ONE $TEST_ONE").replace("$TEST_ONE", "foobar").markup);
Run Code Online (Sandbox Code Playgroud)
警报的值为"foobar $ TEST_ONE".
如果我更改Repeater为以下内容,则Chrome中未替换任何内容:
function Repeater(template) {
var repeater = {
markup: template,
replace: function(pattern, value) {
this.markup = this.markup.replace(new RegExp(pattern, "gm"), value);
}
};
return repeater;
};
Run Code Online (Sandbox Code Playgroud)
......警报是$TEST_ONE $TEST_ONE.
假设我在http://www.foobar.com上托管了一个网站.
有没有办法可以在我的代码中以编程方式确定" http://www.foobar.com/ "(即无需在我的Web配置中对其进行硬编码)?
假设我<div>在页面上有三个元素.我如何交换第一个和第三个的位置<div>?jQuery很好.
是否有内置的lodash函数来实现:
var params = [
{ name: 'foo', input: 'bar' },
{ name: 'baz', input: 'zle' }
];
Run Code Online (Sandbox Code Playgroud)
输出这个:
var output = {
foo: 'bar',
baz: 'zle'
};
Run Code Online (Sandbox Code Playgroud)
现在我只是使用Array.prototype.reduce():
function toHash(array, keyName, valueName) {
return array.reduce(function(dictionary, next) {
dictionary[next[keyName]] = next[valueName];
return dictionary;
}, {});
}
toHash(params, 'name', 'input');
Run Code Online (Sandbox Code Playgroud)
想知道是否有一个lodash捷径.
我正在使用System.Text.RegularExpressions.Regex.IsMatch(testString,regexPattern)在字符串中进行一些搜索.
有没有办法在regexPattern字符串中指定模式应该忽略大小写?(即不使用Regex.IsMatch(testString,regexPattern,RegexOptions.IgnoreCase))
我正在研究指令的模板.如果作用域中的属性设置为true,data-toggle="dropdown"则应将该属性附加到该元素.如果变量为false,则此数据属性不应呈现为元素的属性.
例如,如果scope变量为true,则模板应呈现:
<span data-toggle="dropdown"></span>
Run Code Online (Sandbox Code Playgroud)
如果为false,则模板应呈现:
<span></span>
Run Code Online (Sandbox Code Playgroud)
模板看起来会是什么样的?
例如,我知道我可以ng-class有条件地使用一个类.如果我想要模板渲染:
<span class="dropdown"></span>
Run Code Online (Sandbox Code Playgroud)
然后我的模板看起来像这样:
"<span ng-class="{ 'dropdown': isDropDown }"></span>
Run Code Online (Sandbox Code Playgroud)
如果范围变量isDropDown是false,则模板将简单地呈现:
<span></span>
Run Code Online (Sandbox Code Playgroud)
所以在模板中有一种方法可以有条件地添加一个class="dropdown".模板的语法是否允许我有条件地添加data-toggle="dropdown"?
我为模板尝试过的一件事是:
"<span data-toggle="{ 'dropdown': isDropDown }"></span>
Run Code Online (Sandbox Code Playgroud)
我对上述模板的思考是,如果范围变量isDropDown为true,则值data-toggle将设置为"dropdown".如果isDropDown为false,那么value data-toggle将只是一个空字符串"".但这似乎不起作用.
假设我们有这两个类:
public class Derived : Base
{
public Derived(string s)
: base(s)
{ }
}
public class Base
{
protected Base(string s)
{
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能从内部的构造函数中找出Base那Derived是调用?这就是我想出的:
public class Derived : Base
{
public Derived(string s)
: base(typeof(Derived), s)
{ }
}
public class Base
{
protected Base(Type type, string s)
{
}
}
Run Code Online (Sandbox Code Playgroud)
还有另一种不需要传递的方法typeof(Derived),例如,某种方式在Base构造函数中使用反射吗?
javascript ×4
c# ×3
jquery ×2
regex ×2
angularjs ×1
asp.net ×1
dom ×1
height ×1
inheritance ×1
interlocked ×1
locking ×1
lodash ×1
query-string ×1
reflection ×1
replace ×1
types ×1
url ×1
volatile ×1
webpage ×1