我最近阅读了关于ES6 const关键字的内容,我可以理解它在这样的事情时的重要性:
(function(){
const PI = 3.14;
PI = 3.15; // Uncaught TypeError: Assignment to constant variable
})();
Run Code Online (Sandbox Code Playgroud)
所以,没有人可以改变我的PI变量.
我的误解是我不明白在哪种情况下使用const对象是有意义的(除了阻止人们这样做myObj = newValue;).
(function(){
const obj = {a:1 ,b: 2, c:3};
//obj = {x:7 , y:8, z: 9}
//This is good
//TypeError: Assignment to constant variable.
obj.a=7; obj.b=8 ; obj.c=9;
console.log(obj); //outputs: {a: 7, b: 8, c: 9}
})();
Run Code Online (Sandbox Code Playgroud)
因此,当声明一个对象时:我该说什么时候:现在我必须声明我的对象const?
我们正在研究 Gitlab,每次我开始合并一个分支时,Gitlab 都会默认选中“删除源分支”选项(我认为这很危险)。
由于我不保证我或同事会忘记取消选中此选项并错误地删除分支,因此我想知道是否有解决方案可以默认取消选中它(这是 - 我认为 - 将是更安全)?
当我在 Eclipse 中打开终端时,它默认位于
$> /home/myUserName>$
Run Code Online (Sandbox Code Playgroud)
我希望将其配置为与当前打开的项目位于同一位置。
当我打开位于“/home/userName/path/to/my/personal/projects”的项目“my-project-1”时,我打开终端,它将显示如下:
$> /home/userName/home/userName/path/to/my/personal/projects/my-project-1>$
当我打开位于“/home/userName/path/to/my/personal/projects”的项目“my-project-2”时,我打开终端,它将显示如下:
$> /home/userName/home/userName/path/to/my/personal/projects/my-project-2>$
我正在寻找一种检查对象数组中是否存在对象的好方法.当所有键/值存在于该数组中的同一对象中时,预期结果为true.
通过使用jQuery.grep或在Javascript中的对象数组中查找值返回找到的对象,在JavaScript对象数组中通过id浏览stackoverflow(如find对象)找到的答案.我正在寻找的是一个布尔结果(不是找到的对象).
我知道我可以循环所有数组元素,然后比较每个值....等
但我的意思是,如果有一种方法可以使用这样的JS方法:
var listOfObjecs = [
{id: 1, name: "Name 1", score: 11},
{id: 2, name: "Name 2", score: 22},
{id: 3, name: "Name 3", score: 33},
{id: 4, name: "Name 4", score: 44},
{id: 5, name: "Name 5", score: 55},
];
var isObjectExist = function(search){
return listOfObjecs.filter(function(obj){
if(obj.id===search.id && obj.name===search.name && obj.score===search.score){
return true;
}
return false;
});
}
console.log( isObjectExist({id: 3, name: "Name …Run Code Online (Sandbox Code Playgroud)在开始新问题之前,我总是为它创建一个新的分支(直接来自Gitlab).当我完成该问题的工作(并且测试是好的)时,我创建了一个合并请求(来自Gitlab).
合并完成后,我有一条链接到该合并的" 自动生成 "消息(此消息非常通用,与我完成的所有合并相同).
有些事情发生在我合并develop到master:
有没有办法自定义合并请求消息,以便有这样的消息:
注意:
我正在使用Material-UI Autcomplete组件(免费单人版)并且一切正常,直到我尝试更改文本的颜色(在TextField.
我的代码如下所示:
const moreClasses = {
label: { style: { color: 'blue' } },
input: {
style: {
color: 'red',
borderBottom: `1px solid green`
}
}
};
//...
<Autocomplete
//... classic props as in the official Doc
renderInput={params => <TextField
{...params}
label={'label'}
InputLabelProps={moreClasses.label}
InputProps={moreClasses.input} />
/>
Run Code Online (Sandbox Code Playgroud)
预期行为
当您开始输入时,您可以看到自动完成功能,并且您输入的文本应为红色。
实际行为
文本颜色为红色,但自动完成功能不再起作用。
我创建了这个实时运行示例来说明 3 个组件的问题:
仅文本字段(有效)
使用InputProps(作品)不改变颜色的自动完成
使用更改颜色的自动完成InputProps(不起作用)
笔记
通过设置InputLabelProps自动完成继续工作并更改标签的颜色(在我分享的示例中为蓝色)!所以我无法弄清楚为什么它在设置时不起作用InputProps。
关于这个问题的任何反馈?
我正在使用 Visual Studio 2019 来开发和测试 .NET Core 应用程序。几个月前,我记得我所有的测试都成功了,我能够启动代码覆盖率分析。今天我启动了一个代码覆盖率分析,但它失败了(测试总是成功的):
生成空结果:未检测二进制文件。确保测试已运行,所需的二进制文件已加载,具有匹配的符号文件,并且未通过自定义设置排除在外。有关详细信息,请参阅https://go.microsoft.com/fwlink/?LinkID=253731
我一直在升级我的 Visual Studio,我现在拥有的当前版本是Microsoft Visual Studio Enterprise 2019(版本 16.4.0)
关于这个问题的任何经验或反馈?
我正在使用一个外部服务getListOfItemsFromServiceA,它接受一个id(用户)并返回与该用户关联的 5 个项目(正好 5 个)的列表。
我使用数组解构赋值来设置那些工作正常的项目的值(只是一个例子):
var item1, item2, item3, item4, item5;
//var result = getListOfItemsFromServiceA(1622);
var exampleResult = ['item1', 'item2', 'item3', 'item4', 'item5'];
[item1, item2, item3, item4, item5] = exampleResult;
console.log(item1, item2, item3, item4, item5);Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,在某些情况下,例如在数据库中找不到时getListOfItemsFromServiceA(id)返回。所以我的代码不起作用:nullid
var item1, item2, item3, item4, item5;
//var result = getListOfItemsFromServiceA(1622);
var exampleResult = null;
[item1, item2, item3, item4, item5] = exampleResult;
console.log(item1, item2, item3, item4, item5);Run Code Online (Sandbox Code Playgroud)
有没有办法使用数组析构语法而不是添加 if 条件来解决这个问题if(getListOfItemsFromServiceA(1622) !== null)?
笔记
我正在使用TS Playground来学习 TypeScript。我发现奇怪的是 TypeScript 不会为接口生成特定的代码。
例子:
interface Person {
id: number,
fullName: string,
sayHello: Function
}
let p: Person;
p.id = 123;
p.fullName = 'John Doe';
p.sayHello = function () {return "Hello from " + p.fullName;}
Run Code Online (Sandbox Code Playgroud)
将被翻译为:
var p;
p.id = 123;
p.fullName = 'John Doe';
p.sayHello = function () { return "Hello from " + p.fullName; };
Run Code Online (Sandbox Code Playgroud)
有没有解释为什么 TypeScript 不生成任何代码interface?
我建立了一个五星级的简单组件(用于排名).该组件工作正常.我使用JavaScript来保存结果(当用户点击星形时(这里没有显示)).
我遇到的问题是我没有找到一种正确的方法来模拟mouseover事件(当你将鼠标移过星星并点击之前).所以我用JavaScript做到了.
有没有一种方法只使用CSS来实现这一点(而不是所有那些JS线)?
我正在分享我已经做过的事情.
document.getElementById('star1').addEventListener('mouseover', function(){
this.classList.remove("fa-star-o");
this.classList.add("fa-star");
});
document.getElementById('star1').addEventListener('mouseout', function(){
this.classList.remove("fa-star");
this.classList.add("fa-star-o");
});
document.getElementById('star2').addEventListener('mouseover', function(){
this.classList.remove("fa-star-o");
this.classList.add("fa-star");
document.getElementById('star1').classList.remove("fa-star-o");
document.getElementById('star1').classList.add("fa-star");
});
document.getElementById('star2').addEventListener('mouseout', function(){
this.classList.remove("fa-star");
this.classList.add("fa-star-o");
document.getElementById('star1').classList.remove("fa-star");
document.getElementById('star1').classList.add("fa-star-o");
});
document.getElementById('star3').addEventListener('mouseover', function(){
this.classList.remove("fa-star-o");
this.classList.add("fa-star");
document.getElementById('star1').classList.remove("fa-star-o");
document.getElementById('star1').classList.add("fa-star");
document.getElementById('star2').classList.remove("fa-star-o");
document.getElementById('star2').classList.add("fa-star");
});
document.getElementById('star3').addEventListener('mouseout', function(){
this.classList.remove("fa-star");
this.classList.add("fa-star-o");
document.getElementById('star1').classList.remove("fa-star");
document.getElementById('star1').classList.add("fa-star-o");
document.getElementById('star2').classList.remove("fa-star");
document.getElementById('star2').classList.add("fa-star-o");
});
document.getElementById('star4').addEventListener('mouseover', function(){
this.classList.remove("fa-star-o");
this.classList.add("fa-star");
document.getElementById('star1').classList.remove("fa-star-o");
document.getElementById('star1').classList.add("fa-star");
document.getElementById('star2').classList.remove("fa-star-o");
document.getElementById('star2').classList.add("fa-star");
document.getElementById('star3').classList.remove("fa-star-o");
document.getElementById('star3').classList.add("fa-star");
});
document.getElementById('star4').addEventListener('mouseout', function(){
this.classList.remove("fa-star");
this.classList.add("fa-star-o");
document.getElementById('star1').classList.remove("fa-star");
document.getElementById('star1').classList.add("fa-star-o");
document.getElementById('star2').classList.remove("fa-star");
document.getElementById('star2').classList.add("fa-star-o");
document.getElementById('star3').classList.remove("fa-star");
document.getElementById('star3').classList.add("fa-star-o");
});
document.getElementById('star5').addEventListener('mouseover', function(){
this.classList.remove("fa-star-o");
this.classList.add("fa-star");
document.getElementById('star1').classList.remove("fa-star-o");
document.getElementById('star1').classList.add("fa-star"); …Run Code Online (Sandbox Code Playgroud)javascript ×3
gitlab ×2
arrays ×1
compilation ×1
css ×1
eclipse ×1
font-awesome ×1
material-ui ×1
reactjs ×1
typescript ×1